Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > variable file glob into grep without glob()

Reply
Thread Tools

variable file glob into grep without glob()

 
 
qanda
Guest
Posts: n/a
 
      09-15-2003
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.
 
Reply With Quote
 
 
 
 
Tassilo v. Parseval
Guest
Posts: n/a
 
      09-15-2003
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
glob.glob unicode bug or feature Elbert Lev Python 5 08-02-2004 12:09 AM
Question about glob.glob <--newbie Sean Berry Python 3 05-04-2004 05:34 PM
RE: Bug in glob.glob for files w/o extentions in Windows Tim Peters Python 1 12-01-2003 09:22 AM
Bug in glob.glob for files w/o extentions in Windows Georgy Pruss Python 15 12-01-2003 04:04 AM
pass cmd line file glob to grep for readdir qanda Perl Misc 9 09-11-2003 01:53 PM



Advertisments