Link to home
Start Free TrialLog in
Avatar of blnukem
blnukem

asked on

Global text edit

Hi All

We have sometimes 100’s of web pages to edit on our server and would like a Perl script to do it if possible. The preset variables that I would like to be able to edit would be:

$FolderPath = "the/path/to/the/folder/to/edit";
$ExtentionToEdit = "htm";
$LookFor = "look for text like this and change it";
$Replace = "This is my new text for this file";

Thanxs!
Avatar of holli
holli

use File::Find;

$FolderPath = "the/path/to/the/folder/to/edit";
$ExtentionToEdit = "htm";
$LookFor = "look for text like this and change it";
$Replace = "This is my new text for this file";

find(\&wanted, $FolderPath);

sub wanted
{
      if ( $File::Find::name =~ /$ExtentionToEdit$/ && -f $File::Find::name )
      {
            system ("perl -ni.bak -e \"s/$LookFor/$Replace/; print;\" $File::Find::name\"");
      }
}
Avatar of blnukem

ASKER

holli

I get this error:

sh: -c: line 1: unexpected EOF while looking for matching `"'
sh: -c: line 2: syntax error: unexpected end of file

I would really like to accomplish this with the use of modules some of our serverdont have all modules installed.
you will have to add the shebang-line at the beginning of the script. like:

#!/usr/bin/perl

the line must point to the correct path of your perl interpreter.
Avatar of blnukem

ASKER

I did

#!/usr/bin/perl

use File::Find;

$FolderPath = "/usr/local/etc/httpd/htdocs/test";
$ExtentionToEdit = "htm";
$LookFor = "Old Words";
$Replace = "New Words";

find(\&wanted, $FolderPath);

sub wanted {

     if ( $File::Find::name =~ /$ExtentionToEdit$/ && -f $File::Find::name ){
          system ("perl -ni.bak -e \"s/$LookFor/$Replace/; print;\" $File::Find::name\"");
     }
}
print "Content-type: text/html\n\n";
print "done";
and?
Avatar of blnukem

ASKER

I get this error:

sh: -c: line 1: unexpected EOF while looking for matching `"'
sh: -c: line 2: syntax error: unexpected end of file
you are still exexuting the script to the shell not through perl!

try typing

perl scriptname

at the command-line
what's the output of the following

#!/usr/bin/perl
@a = ("hello ", "from ", "perl ");
print "@a;

??
Avatar of blnukem

ASKER

hello from perl
ASKER CERTIFIED SOLUTION
Avatar of holli
holli

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of blnukem

ASKER

Thanxs!