Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: using wildcard character * in perlscript command line

by BrowserUk (Pope)
on Jan 28, 2005 at 15:19 UTC ( #425984=note: print w/ replies, xml ) Need Help??


in reply to using wildcard character * in perlscript command line

glob applied to @ARGV in a BEGIN block gives a reasonable approximation.

perl -wle"BEGIN{ @ARGV = map glob, @ARGV } print for @ARGV" *

Examine what is said, not who speaks.
Silence betokens consent.
Love the truth but pardon error.


Comment on Re: using wildcard character * in perlscript command line
Download Code
Re^2: using wildcard character * in perlscript command line
by holli (Monsignor) on Jan 28, 2005 at 15:41 UTC
    I looked at this and thought, "no way, what if the script gets switches or other arguments that are not files (like script * -option), those arguments will get lost because they donīt match any filename.
    But they donīt. Can you explain why?

    holli, regexed monk
      Because glob() will simply pass-thru anything that doesn't need expansion, otherwise it would lose ordinary filenames. But if the 'option' might have the expandable characters '*' or '?' you will be in danger of losing _those_ options. glob('-f?') returns nothing (usually), though glob('-f') will simply return '-f'.

      If the value passed to glob doesn't contain a wildcard, it is passed through untouched.

      P:\test>perl -wle" print for glob '-debug' " -debug

      As for the why, if there is no file of that name existing, you'll need someone with the historical perspective (merlyn?).

      Maybe, just so that it doesn't affect non-wildcard parameters?


      Examine what is said, not who speaks.
      Silence betokens consent.
      Love the truth but pardon error.

      Perl's glob was originally implemented in terms of csh's. From man csh:

      If a word contains any of the characters *, ?, [ or { or begins with the character ~ it is a candidate for filename substitution, also known as globbing.

      If you use the bsdglob function from File::Glob (which is how glob is implemented nowadays), you can pick behaviour as desired.

      Makeshifts last the longest.

      For the same reason for which (depending on an option, really) *NIX shells (well, at least bash that I know) pass through any unmatched item.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://425984]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (12)
As of 2014-09-01 12:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (7 votes), past polls