I was just reading something about something similar to this is the Perl Cookbook. Where you could seek() back to the begining on the perl sciprt and actually parse the script from the script. weird yet none the less, cool.
however I don't think this is what you want to be doing in this case.. I think what you want to do is something similar to what adamsj suggested by rewriting your script to either take command line args as filenames, or "piping" the file names to the script ie:
ls files.* | script.pl
OR
./script.pl files.ext files.ext2 files.ext3
or something else to that extent..
be creative, but account for as many cases as you can think of.. if the files are going to be located in the same place and/or named the same thing.. maybe you only want to pass the directory where the files are and/or the file prefix/suffix to open.. that way you can use an opendir(), readdir() and match files with regular expressions so you can have stuff like:
./script.pl -d /my/dir/for/files -f files
and in the script:
....
$defaultdir = "/usual/place/to/look";
$dir = $opt_d;
$dir = $defdir unless -e $dir;
$defprefix = "files\.";
$prefix = $opt_f;
$prefix = $defprefix unless $prefix;
opendir(LS, $dir) || die "couldn't open dir\n";
while(my $file = readdir(DIR)) {
if($file =~ /^$prefix/) {
push @FILES,$file;
}
}
....
then do what adamsj suggested, open each file in @FILES, check the first line, then send the file name or filehandle to the subroutine and have the subroutine open the file or seek to the beginning of the file handle.
just a few ideas..
-brad..
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.