Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re: Useful addition to Perl?

by BrowserUk (Pope)
on Mar 05, 2004 at 08:52 UTC ( #334167=note: print w/replies, xml ) Need Help??

in reply to Useful addition to Perl?

I really like this idea. I'd also like to see a -g option for non-globbing platforms that would would glob @ARGV for those of use who use systems that do not do this by default. Actually, as I've recently discovered, it would be useful on systems who's shells do glob by default. It would be a way of alleviating the "list too long" problem.

I have a module called that does this for me currently using -Mg, and I like the idea enough that if you or someone make a module that does this I'll be adding it to my system as

A compromise solution to putting this is the core might be to have the command line options processing in the perl executable attempt a "use X" where X is any unknown command line option it encounters. If the "use r;" (or g etc) failed, it would then report the "unknown option" in the normal way. Then we could use commands like

perl -grple ' next unless /..../' \*.log

One possible problem with implementing this as a module (using File::Find or similar) is that @ARGV can end up containing a huge list on large/deeeply nested subtrees. It would be nice to find a way of processing @ARGV such that each new level of subtree was only expanded when needed. It's difficult to explain what I mean but for example:

  1. @ARGV = '*';

    So this gets globbed @ARGV = glob @ARGV;

  2. Now @ARGV = ( file1, file2, file3, dir1, dir2 );

    Perl enters the normal <> processing loop and processes the three files, but when it encounters the first directory, that directory is then globed, with any directories that result beig unshifted onto @ARGV before any files.

  3. So you get @ARGV = ( dir1/file1, dir1/file2, dir1/sub1, dir1/sub2, dir2 );

    And the process repeats, working it's way through the subtree processing files as they are encountered and decending into directories as it goes until @ARGV is empty.

Thats probably not well thought through, but the idea is there. I guess one advantage of sticking with the -Mr syntax would be that you could add additional options like -Mr=d for depth first ot -Mr=b for breadth first etc.

Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail

Replies are listed 'Best First'.
Re: Re: Useful addition to Perl?
by Jenda (Abbot) on Mar 05, 2004 at 21:50 UTC
    I have a module called that does this for me currently using -Mg, ...

    Something like my (US mirror) ? ;-)

    Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.
       -- Rick Osborne

    Edit by castaway: Closed small tag in signature

      Yes. almost exactly like your Thanks.

      Actually, I have your on my other machine, but when I set this one up, I couldn't remember where I got it -- my portable was dead at the time with a flaky motherboard connection. Then I came across a description of something called "" which I cut and paste but then got fed up with typing -mWild and renamed it to

      So yes, probably very similar, and I definitely stole the name from you--I'd gotten used to it. Thanks:)

      Now you've reminded me of where I got it from in the first place, I'll probably grab yours again (and rename it (I just tried but your site seems to be off the air at this moment).

      Examine what is said, not who speaks.
      "Efficiency is intelligent laziness." -David Dunham
      "Think for yourself!" - Abigail
Re: Re: Useful addition to Perl?
by etcshadow (Priest) on Mar 05, 2004 at 20:41 UTC
    Big ++.

    I obviously agree very much. In fact, some of this stuff (like avoiding exploding @ARGV) are in my discussions of (in this thread and in its own thread, elsewhere). The nice thing about the way that -n or -p are actually processed (which is with while (<>) { ... }) is that they actually shift @ARGV. Thus, by tieing @ARGV and only exploding directory contents as they are fetched, you can do a highly efficient "perl -mr -ne ...".

    I'm also a big fan of the glob thing... I even considered doing that automatically in, if $^0 =~ /MSWin32/. I decided, though, to fight one battle at a time.

    Last of all, I totally love the idea of treating otherwise unrecognized switches as uses. ...Well, love the idea of it, and the cuteness... but of course, you run out of switches *real* fast, and actually, they're mostly already used up. Of course, if you want to get more into the perlrun mindset that gives us the -s option to perl, perhaps we would only activate this behavior with another special switch... or maybe a switch that leads a group of "external" switch modules... -X seems to be available. That would give you something like

    perl -Xrg -ple '...' *
    as a shorthand for
    perl -Mr -Mg -ple '...' *
    But, anyway... now I feel that I have clearly strayed off into hyperspace =D
    ------------ :Wq Not an editor command: Wq

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://334167]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (3)
As of 2017-06-29 06:00 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (653 votes). Check out past polls.