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!
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
$ExtentionToEdit = "htm";
$LookFor = "look for text like this and change it";
$Replace = "This is my new text for this file";
Thanxs!
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.
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.
#!/usr/bin/perl
the line must point to the correct path of your perl interpreter.
ASKER
I did
#!/usr/bin/perl
use File::Find;
$FolderPath = "/usr/local/etc/httpd/htdo cs/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";
#!/usr/bin/perl
use File::Find;
$FolderPath = "/usr/local/etc/httpd/htdo
$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?
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
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
try typing
perl scriptname
at the command-line
what's the output of the following
#!/usr/bin/perl
@a = ("hello ", "from ", "perl ");
print "@a;
??
#!/usr/bin/perl
@a = ("hello ", "from ", "perl ");
print "@a;
??
ASKER
hello from perl
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanxs!
$FolderPath = "the/path/to/the/folder/to
$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\"");
}
}