Chris McMahon wrote: > > That helped, and I found a Merlyn post on perlmonks, see below, > which turned out to be a little too magical for me. So the code below > is working, but parts of it still look strange to me, particularly the > part where I read the boilerplate from a file inside of the while<>. > Any suggestions for improvements would be welcome. (Note, this is > Win32...) > > use warnings; > use strict; > use File::Find; > use File::Slurp; > > #adapted from Randal Schwartz here: > http://www.perlmonks.com/index.pl?node_id=115428 > > { > my @starters = @ARGV ? @ARGV : 'C:/test/'; > @ARGV = ();
The original used a list for the starting directory although using a scalar won't hurt because @starters forces list context. The trailing slash on the directory name is superfluous. You can clear @ARGV and assign from it using splice. my @starters = @ARGV ? splice @ARGV : qw(C:/test); > find sub { > if ($_ ne ".") { #WHAT IS THIS "." FILE? SOME WINDOWS THING? Most modern file systems have two files in every directory named '.' and '..'. '.' represents the current directory and '..' represents the parent directory. You should probably test that the name in $_ is a file and not a directory. > push @ARGV, "$File::Find::dir/$_"; File::Find provides the $File::Find::name variable which contains the same data as "$File::Find::dir/$_". push @ARGV, $File::Find::name if -f; > } > }, @starters; > } > > { > local $/; # slurp it You are using the File::Slurp module to slurp the files so you don't need this. > #local $^I; # = ".bak"; #NO BACKUP! YIKES! (gotta do 17,000 of 'em, no > room) It appears that you are not using $^I and therefore not using the in-place edit feature. > while (<>) { If you are not using in-place edit then you should just use "foreach ( @ARGV ) {}" > my @path = split /\//, $ARGV; > my $boilerplate = read_file( 'bp.txt' ); #READ THIS FILE 17000 > TIMES!? You should only do this once outside the loop > $boilerplate =~ s/REPLACEME/$path[$#path]/g; #Replace string > "REPLACEME" with current filename. > my $file = read_file( $ARGV ); > my $towrite = "$boilerplate$file"; > open (OUT, ">$ARGV"); #dangerous, but what the heck... You should *ALWAYS* verify that the file opened correctly. > print OUT $towrite; > > } > } It looks like you want something like this: use warnings; use strict; use File::Find; use File::Slurp; use File::Basename; { my @starters = @ARGV ? splice @ARGV : qw(C:/test); find sub { push @ARGV, $File::Find::name if -f }, @starters; } my $boilerplate = read_file( 'bp.txt' ); for my $path ( @ARGV ) { my $file = basename $path; ( my $new = $boilerplate ) =~ s/REPLACEME/$file/g; my $data = read_file( $path ); write_file( $path, "$new$data" ); } __END__ John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>