Hi Richard. Richard Fernandez wrote: > I just had a situation where I needed to replace one string with > another string in 200 files. > This is what I came up with, but I know there has to be a better way. > Below is my code. > > "myfiles" contains a list of the files I need to scrub, one per line. > > -------8<-----------------8<----------------------- > #!/usr/local/bin/perl -w > use strict; > $|++; > > > my @files = `cat myfiles` or die; > for (@files) { > > chomp; > push @ARGV, $_; > } > $^I = ".bak"; # Got this from a previous message; thanks Peter! > while (<>) { > > s#/u01/app/webMethodsFCS#/u02/app/webMethodsFCSclone#g; > print; > > }
I don't think there's a better way, but it's a lot neater like this: #!/usr/local/bin/perl -i.bak use strict; use warnings; @ARGV = ( 'myfiles' ); my @files = <>; chomp @files; @ARGV = @files; while (<>) { s(/u01/app/webMethodsFCS)(/u02/app/webMethodsFCSclone)g; print; } __END__ > ---------8<------------------8<----------------------- > > Seems to me there should be a way to provide the filenames on the > command line > w/o having to read the list into an array first, but I tried using > xargs (this is unix) and a couple > of other things but couldn't figure it out. @ARGV contains the (globbed, if you're on Unix) list of files on the command line. You can alter @ARGV to pretend that something was there. Can't remember my Unix too well, but doesn't script @myfiles do what you want? Cheers, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]