Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Command Line Open Files

by Herkum (Parson)
on Sep 14, 2009 at 22:47 UTC ( #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 (Pope) 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
Node Status?
node history
Node Type: perlquestion [id://795235]
Approved by ikegami
Front-paged by tye
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2017-12-12 08:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (327 votes). Check out past polls.

    Notices?