searching contents of html file

Ken Elliott's picture

They have: 358 posts

Joined: Jun 1999

Hello.

Simple perl question. I have to make changes to about 120+ webpages that all where constructed using the same template. But I have to add some text to each one. Surely there is a way for me to write a perl script that will search through the contents of each file and find and replace some selected text.

I really don't even have a guess as to how to do it. I've checked my perl book, but it is not a complete guide..it just points out the basics.

Thanks for all your help.
VulKen
BOLD

Pimpin like a pimp with an electrofied pimpin machine!

They have: 453 posts

Joined: Jan 1999

Hi,

perldoc File::Find
should help you with finding the files.

Replacing the text depends on how complicated the change is,
but something like

while( <IN> ){
  s/OLD/NEW/g;
  print OUT $_;
}
'

Should do it.
If you have multiline changes it gets a bit more complicated (see perldoc perlre)
If you have "dynamic" input you have to write a small state machine.

If you have been using a template,
why didn't you build the whole site from the template in the first place ?
Use WML.
Or write a small perl-script that merges your template and content.
Never just copy'n'paste template with your editor.

ciao
Anti

Ken Elliott's picture

They have: 358 posts

Joined: Jun 1999

Well anti, if I need to explain my pages. They where created by a perl script, so that some numbscull could develop and edit these pages without any knowledge of html.

They are simple pop up windows that tell about our exhibitors. I will try to implement the script you suggested. I'll let you know how it goes.

Thanks for your help.
VulKen

Oh, I would have used SSI, but the server doesn't support it. Since this is not a personal website, I cannot change servers. So I have to deal with what I got.

IRS motto: We got what it takes, to take what you got

Pimpin like a pimp with an electrofied pimpin machine!

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.