Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

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> 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?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://795235]
Approved by ikegami
Front-paged by tye
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (9)
As of 2018-07-18 11:00 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (389 votes). Check out past polls.