#!C:\Perl
####
perl path/file_name_of_script arg1 ...
####
#!/usr/bin/perl
####
path/file_name_of_script arg1 ...
####
#!/usr/bin/perl
use strict;
use Getopt::Long;
my $Usage = "Usage: $0 [-p path] filename.list\n or: ls [path] | $0 [-p path]\n";
my $path = '.';
die $Usage unless ( GetOptions( 'p=s' => \$path ) and -d $path );
die $Usage if (( @ARGV and !-f $ARGV[0] ) or ( @ARGV==0 and -t ));
# need file name args or pipeline input
my @file_list = <>; # read all input as a list of file names
chomp @file_list; # get rid of line-feeds
for my $name ( @file_list ) {
my $file = "$path/$name";
if ( ! -f $file ) {
warn "input value '$file' does not seem to be a data file; skipped\n";
next;
}
if ( ! open( I, "<", $file )) {
warn "open failed for input file '$file'; skipped\n";
next;
}
...
}