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

Jon Amundsen jamundsen at jamundsen.dyndns.org
Tue Sep 16 14:29:20 CDT 2003


Walter,

How about using the -i switch followed by an extension.  Something like perl -i.old -e 'code'.  This does away with the -o switch and renames the original file to be .old.  But it should handle each file separately and handle wildcards on the commandline.

Regards,

On Tue, Sep 16, 2003 at 02:03:56PM -0500, Walter Torres wrote:
> 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
> 
> 
> _______________________________________________
> Chicago-talk mailing list
> Chicago-talk at mail.pm.org
> http://mail.pm.org/mailman/listinfo/chicago-talk

-- 
Jon Amundsen
jamundsen at jamundsen.dyndns.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: not available
Url : http://mail.pm.org/pipermail/chicago-talk/attachments/20030916/0be35e93/attachment.bin


More information about the Chicago-talk mailing list