Web Hosting Talk







View Full Version : [PERL] - Simple perl question...


hypernatic.net
04-05-2002, 03:01 PM
Okay,

I have a script who changes lines in a specific file.
For instance, it finds the line "Hello World!" it changes it to "Hello Planet!"

This is only done when I specify the $file... So it's not a "change all files in a directory" kind of thing...

HOW do I make it that way? So that it does an "ls -a" and starts with file1, then file2, etc etc...

HOW? :D

(SH)Saeed
04-05-2002, 03:11 PM
I would suggest you take a look at the opendir() and readdir() functions in Perl.

TIP: First you open a dir and then you read it :D

cgiGeek
04-05-2002, 05:32 PM
Ii is not just a small modification,
but almost a rewrite of the script.

B.

taz0
04-05-2002, 05:55 PM
ls -1 | while read file
do
mv $file $file.old
sed s/World/Planet/g < $file.old > $file
done

It is shorter than the Perl code.

hypernatic.net
04-05-2002, 05:56 PM
I bought a script for MrAmazon... Works great!! THANXX