http://www.perlmonks.org?node_id=795235

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.