Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Command Line Open Files

by Herkum (Parson)
on Sep 14, 2009 at 22:47 UTC ( [id://795235]=perlquestion: print w/replies, xml ) Need Help??

Herkum has asked for the wisdom of the Perl Monks concerning the following question:

I was asked by a co-worker to write script to parse some XML files. Some of the options he came up with were,

  1. Open a file in the current directory(easy enough).
  2. Open files in the current directory(Use parsing on a splat, easy enough).
  3. Open files relatively/abosolutely located in another directory using the splat(More parsing, that is annoying).

This is fairly common syntax so there has to be a module which handles this sort of request. I have no idea what to look for though. Suggestions?

Update: Just to be clear, this was about me getting the list of files form the command line for use in my script. Example:

#myprompt>parse_xml.pl foo/bar/*.xml

Replies are listed 'Best First'.
Re: Command Line Open Files
by ikegami (Patriarch) on Sep 14, 2009 at 23:05 UTC

    In unix, this is already done by the shell

    $ perl -le'print for @ARGV' a.xml a.xml $ perl -le'print for @ARGV' *.xml a.xml b.xml $ perl -le'print for @ARGV' foo/*.xml foo/x.xml foo/y.xml

    To handle Windows too, you just need to add the following code to your script:

    BEGIN { if ($^O =~ /MSWin32/) { require File::Glob; @ARGV = map File::Glob::bsd_glob($_), @ARGV; } }

      I am glad I asked, I did not even know about that.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://795235]
Approved by ikegami
Front-paged by tye
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2024-04-19 01:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found