variable file glob into grep without glob()

Ask a Question related to PERL Miscellaneous, Design and Development.

  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. Similar Questions and Discussions

    1. File::Glob bug ?
      The following script: use File::Glob ':glob'; my @test = ( '{random string}', '\\{random string\\}' ); for (@test) {
    2. File::Glob can't load module [cygwin], perl-5.8.4 9 (newbie)
      I am playing with compiling Perl 5.8.4 under cygwin. Can anyone help me fix the error I seem not get past? ../perl harness Can't load module...
    3. pass cmd line file glob to grep for readdir
      Hi all I want to process lots of files (too many for the shell to expand on one line) so I use readdir instead of glob. If I know the file glob...
    4. Variable instaed of GLOB REF
      Howdy all! If you have a function that is expecting a FILEHANDLE as it's argument how could you supply it a variable instead? For instance: ...
    5. file name of file that reference to type glob points to
      Hey all. This is probably a elementary question, but I can't seem to be able to find a builtin function or combination of functions that will let...
  3. #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$&."'!#+sexisexi ixesixeseg;y~\n~~dddd;eval
    Tassilo v. Parseval Guest

Posting Permissions

  • You may not post new threads
  • You may 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