--thanks all (chris, jeff, nikola)
--jeff: your suggestion worked like elfin magick. thanks! --(note: i had to do this twice ... in the search pattern --i forgot the "$" in "newpattern" ... oops.) --anyways ... -X -----Original Message----- From: Jeff 'japhy' Pinyan [mailto:[EMAIL PROTECTED]] >* open each file >* search and replace the old pattern to a new pattern >(should only be one occurrence) >* close file You're not storing the results anywhere. You can't expect Perl to modify the file for you automagically. >But nothing is happening (that I can see). >What am I doing wrong? You can use Perl's special in-place modification idiom: >use diagnostics; That's probably not needed in your program. Why didn't you use strict; though? >for my $file(@list) { >open (FILE, $file ) or die "can nae open the file: $!";; >while (<FILE>) { > s!$pattern!newpattern!g ; > } # end while loop >} #end of for loop > >close (FILE); You should place the close(FILE) INSIDE the for loop, not outside it. Anyway, here's the nifty idiom: { local $^I = ".bak"; # to keep a backup of your files # set to "" if you don't want any backups local @ARGV = @list; # the files to work on while (<>) { s/$pattern/newpattern/g; print; } } Poof! Like magic, Perl takes care of everything for you. Read up on 'perldoc perlvar' to find out more about $^I and magical in-place editing.
