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

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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 g.pm 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 r.pm.

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

In reply to Re: Useful addition to Perl? by BrowserUk
in thread Useful addition to Perl? by tilly

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-04-25 17:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found