# No.46 Perl Sample (code key - 76) # Learning Perl: take more than one argument (複数のファイルをコマンドラインから取る) # Tomonori Nagano # Last Update: January 18, 2008 # # This file is encoded in Unicode (UTF-8). If you see gibberish characters, # please re-encode the file in utf-8. # if ($#ARGV < 0) { # error if there is no argument die "usage: perl concatenate.pl filename1 filename2 filename3 ...:$!\n" ; } @allfiles = @ARGV ; # take the all arguments into an array for (my $j=0; $j<= $#allfiles ; $j++) { # iterate all files my $filename = pop @allfiles ; # pop a filename from the array chomp ($filename) ; # chomp the filename (unnecessary?) open (INFILE,"$filename") or die "cannot open $filename:$!\n" ; # open the file with handlename of INFILE while (){ # process INFILE push (@data,$_) ; # push each line into an array } close (INFILE) ; # close INFILE }