seattlejohn has asked for the wisdom of the Perl Monks concerning the following question:
I've got a command-line script that needs to run on multiple platforms, specifically Windows (both with and without Cygwin) and Un*x. The script takes a list of files and does some munging on them:
munge.pl a.txt b.txt c.txt
The issue arises when I process command-line args that contain wildcards:
munge.pl *.txt *.xml
bash seems to expand the wildcards into matching filenames before passing them to the perl script, whereas Windows just passes the arguments with wildcards intact.
Since I'd like behavior to be consistent (DWIM!) on both platforms, I experimented with using this code at the beginning of my script:
push @files, glob($_) foreach @ARGV;
This appears to have the desired effect: on Windows it forces the wildcards to expand, and on Cygwin/Linux it doesn't change anything because the wildcards have already been expanded.
My question for the wise folks here in the Monastery is: Is this a reasonably safe approach? Or have I opened myself up to sneaky problems I haven't thought about? Are there better ways to accomplish this task? (Search here didn't turn up much, but maybe I'm not asking the question in the right way...)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: portable globbing behavior for command-line tool
by rsteinke (Scribe) on Jul 04, 2002 at 06:28 UTC | |
by seattlejohn (Deacon) on Jul 04, 2002 at 06:35 UTC | |
|
Re: portable globbing behavior for command-line tool
by bronto (Priest) on Jul 04, 2002 at 08:28 UTC | |
by seattlejohn (Deacon) on Jul 04, 2002 at 17:40 UTC | |
|
Re: portable globbing behavior for command-line tool
by rinceWind (Monsignor) on Jul 04, 2002 at 08:27 UTC | |
by Abigail-II (Bishop) on Jul 04, 2002 at 09:50 UTC |