[Chicago-talk] Q on '-n' and wildcards

Walter Torres walter at torres.ws
Tue Sep 16 14:03:56 CDT 2003


A new question, about wildcards.

I have a script I wrote sometime ago that accepted and processed wildcard
parameters...

   use File::KGlob;
   @files = glob ( "*.txt" );

That worked just fine.

Now I'm trying to use a new technique (for me) the -n -s (as suggested by
Mark and Andy).

I have a test script that accepts filenames from the command line, pulls out
the '-o' (mine) filename for the results to be placed.

   > test3.pl demo_1.log demo_2.log demo_3.log -0 results.log

It opens each file and runs down the contents, spitting them out to the
result.log just fine.

Next step is to handle wild cards...

   > test3.pl demo_*.log -0 results.log

Anyone have any pointers on how to "upgrade" my script to handle wild cards?

Also, the current incarnation of my script places all results into a single
file.

I have a desire to place the results of each file in their own log file, in
a different directory.

   > test3.pl demo_*.log -0 /new/path

This should place the results of our munging into a file of the same name as
the original in the given directory.

I know how to handle coding when the file is over...

# built-in loop begins here ================================
   # This technique uses Perl built-in methods to
   # handle multiple files and iterate through each
   # file in turn. Makes life a bit easier!

   # We will need to munge each row in turn, later
   # This just spits out the file name and row number
   print RESULT "$ARGV: $.\n";

   # Place end data into log file
   # Name of file and number of records processed
   &to_log("FILE: $ARGV $. records") if (eof);

# built-in loop ends here ==================================


So, I guess I' asking, is there a START_OF_FILE sort of thing?

I need to open a new RESULT file each time Perl opens an a new input file.

Any pointers, doc URLS, etc that I can read up on this?

I've searched and read till me eyes hurt. I've found nothing, but then
again, I figure I'm not asking the right questions.

Thanks for your help.

Walter





More information about the Chicago-talk mailing list