Professional Web Applications Themes

variable file glob into grep without glob() - PERL Miscellaneous

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 ...

  1. #1

    Default variable file glob into grep without glob()

    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 Guest

  2. #2

    Default Re: variable file glob into grep without glob()

    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$&."'!#+ii ixesixeseg;y~\n~~dddd;eval
    Tassilo v. Parseval Guest

Similar Threads

  1. File::Glob bug ?
    By Jaap Karssenberg in forum PERL Modules
    Replies: 0
    Last Post: June 28th, 01:39 AM
  2. Replies: 0
    Last Post: June 13th, 10:13 PM
  3. pass cmd line file glob to grep for readdir
    By qanda in forum PERL Miscellaneous
    Replies: 9
    Last Post: September 11th, 01:53 PM
  4. Variable instaed of GLOB REF
    By Dan Muey in forum PERL Beginners
    Replies: 4
    Last Post: August 18th, 07:36 PM
  5. Replies: 3
    Last Post: July 1st, 03:56 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139