You can use magic! Just have the first parameter be the file you want to save to, and then just list all the files you want to read from. Here is an example
#!/usr/local/bin/perl
my $outfile = shift; # You have to use shift here for magic to work
open (OUT, ">$outfile") || die $!;
while (<>){ # This is magic, it opens all the files that are on @ARGV
print OUT $_;
}
close (OUT);
You would call it like this 'myprog.pl outfile file1 file2 file3' | [reply] [d/l] |
What if you would have the files been selected from a select menu. Like one dropdown with one file name and another with the other file name using a form to submit the information and display results to the browser window?
| [reply] |
use CGI;
my $q = new CGI; # Get a CGI object
open (OUT, ">$q->param('outfile')") || die $!; # Open our output file
my @files = grep{/^file\d+$/} $q->param(); # Grab a list of params
for my $filename (@files){
open (IN, $q->param($filename)) || die $!; # Open each input file
print OUT <IN>; # Print the input file to the output file
close (IN); # Make sure you close the input file
}
close (OUT);
| [reply] [d/l] |
I want to just combine or append a line to the beginning of a file. Is the processing complexity as low to do the following?
open (OUT, ">$q->param('outfile')") || die $!; # Open our output file
open (IN, $q->param($filename)) || die $!; # Open each input file
print OUT <IN>; # Print the input file to the output file
close (IN); # Make sure you close the input file
close (OUT);
vs. over external command such as:
`copy $file1+$file2 fileout`;
| [reply] |