variable file glob into grep without glob()

Discussion in 'Perl Misc' started by qanda, Sep 15, 2003.

  1. qanda

    qanda Guest

    Hope I don't get shot for posting again, but I really need help with
    this ...

    I want to process lots (thousands) of files. I want to take a file
    glob from the command line and pass it into a grep. If I could write
    the file glob (file*.ext for example) directly I would do ...

    local @ARGV = grep /file.*\.ext/, readir CURDIR;

    However I need to take the glob from the command line. I can't use
    the Perl glob as I am restricted to Perl 5.005 which dosen't work with
    large argument strings and the only overhead I want for the user is to
    possibly quote the glob, maybe myscript "file*.ext"; I do not want
    them using find and/or xargs.

    Thanks.
     
    qanda, Sep 15, 2003
    #1
    1. Advertising

  2. Also sprach qanda:

    > Hope I don't get shot for posting again, but I really need help with
    > this ...
    >
    > I want to process lots (thousands) of files. I want to take a file
    > glob from the command line and pass it into a grep. If I could write
    > the file glob (file*.ext for example) directly I would do ...
    >
    > local @ARGV = grep /file.*\.ext/, readir CURDIR;
    >
    > However I need to take the glob from the command line. I can't use
    > the Perl glob as I am restricted to Perl 5.005 which dosen't work with
    > large argument strings and the only overhead I want for the user is to
    > possibly quote the glob, maybe myscript "file*.ext"; I do not want
    > them using find and/or xargs.


    In this case translate the glob pattern into a regular expression. You
    don't have to do that yourself but let Text::Glob from the CPAN do this
    work for you:

    use Text::Glob qw(glob_to_regex);
    ...
    my $pat = glob_to_regex(shift);
    local @ARGV = grep /$pat/, readir CURDIR;

    Tassilo
    --
    $_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
    pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
    $_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
     
    Tassilo v. Parseval, Sep 15, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Georgy Pruss
    Replies:
    15
    Views:
    757
    Tim Roberts
    Dec 1, 2003
  2. Tim Peters
    Replies:
    1
    Views:
    383
    Duncan Booth
    Dec 1, 2003
  3. Sean Berry

    Question about glob.glob <--newbie

    Sean Berry, May 4, 2004, in forum: Python
    Replies:
    3
    Views:
    359
    David M. Cooke
    May 4, 2004
  4. Elbert Lev

    glob.glob unicode bug or feature

    Elbert Lev, Jul 31, 2004, in forum: Python
    Replies:
    5
    Views:
    419
    Neil Hodgson
    Aug 2, 2004
  5. qanda
    Replies:
    9
    Views:
    181
    qanda
    Sep 11, 2003
Loading...

Share This Page