I'm a little confused. You said you are running on macosx, but your code starts with:
#!C:\Perl
That makes no sense, and it entails that you can only run the script with a command line like this:
perl path/file_name_of_script arg1 ...
(where the "path/" part is only needed if the script is not in your shell's current working directory). I would use this as the initial "shebang" line:
#!/usr/bin/perl
because macosx is really a unix OS, and in unix, perl is typically found in the /usr/bin/ directory; macosx definitely has perl in that location. With that as the shebang line, and doing the shell command "chmod +x file_name_of_script", the script becomes available as a shell command:
path/file_name_of_script arg1 ...
where the "path/" part is only needed if your shell PATH variable does not include the directory where the script is stored.

As for your question about iterating over a list of file names, a method that I find useful goes like this: the perl script expects as input a list of file names, loads those into an array, and then iterates over the array. At each iteration, if there's a problem with the file or its contents, issue a warning and skip on to the next file in the list; e.g.:

#!/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; ski +pped\n"; next; } if ( ! open( I, "<", $file )) { warn "open failed for input file '$file'; skipped\n"; next; } ... }
There are already very good shell command tools for creating a list of file names ("ls", "find"), and for filtering lists ("grep"), so I'm inclined not to rewrite those things in a perl script that is supposed to process a list of file names.

The exception to that rule is when the script is really intended for a specific task that always involves a specific location and/or filter for getting its list of file names to work on, because in that case, I'd rather not have to repeat the selection process on the command line every time I run the script.


In reply to Re^3: Piping many individual files into a single perl script by graff
in thread Piping many individual files into a single perl script by kelder

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.