in reply to special context of file names in array?
It is difficult to decipher exactly what you are trying to do from your description and code. If I understand, then the code below should work. It is most definitely not how I would normally write such a routine but I didn't want to put too much time in as I wasn't even sure it would do what you wanted. So, I used backticks with cat (as you did), slurped in all of the files, and used a minimal amount of error checking.
It'll take the file names given on the command line and create new files with "new_" prepended to the original names that contain the contents of the file sandwiched between the contents of the files header.txt and footer.txt.
#!/usr/bin/perl -w use strict; sub add_header_and_footer_to_files { my @files = @_; my $header = `cat header.txt`; my $footer = `cat footer.txt`; for my $filename (@files) { my $file = `cat $filename`; open OUT, '>', "new_$filename" or die "Couldn't open $filename.new for writing: $!\n"; print OUT $header, $file, $footer; } } add_header_and_footer_to_files(@ARGV);
Good luck!
-sauoq "My two cents aren't worth a dime.";
|
|---|