# No.4 Perl Sample (code key - 32) # Dir Access: Concatenating all files in a directory (全てのファイルをつなぎ合わせる) # 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. # #!/usr/bin/perl $dirname = $ARGV[0] ; opendir(DIR,$dirname) or die "couldn't opne the directory: $!"; @allfiles = grep !/^\.\.?$/, readdir DIR; # removing . and .. closedir DIR; # process the files in the directory for (my $j=0; $j<= $#allfiles ; $j++) { my $filename = $allfiles[$j] ; chomp ($filename) ; open (INFILE,"$dirname/$filename") ; while (){ push (@data,$_) ; } close (INFILE) ; } foreach (@data){ print $_ ; }