Ask a Question related to PERL Miscellaneous, Design and Development.
-
qanda #1
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
to use such as file*.ext I can put this directly into the grep ...
local @ARGV = grep /file.*\.ext/, readir CURDIR;
My question is how can I take a file glob on the command line and
transform it into an expression for grep. I suppose this also implies
we must prevent the shell from expanding by quoting the expression
such as myscript *file*.ext"
Thanks.
qanda Guest
-
File::Glob bug ?
The following script: use File::Glob ':glob'; my @test = ( '{random string}', '\\{random string\\}' ); for (@test) { -
grep text by line....anyone pls?
how to grep text by line? anyone can help to guide me. -
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... -
grep binary file detection
Hi all, When I grep through my mbox files, the ones that I imported from Outlook Express return "binary file matches". I have run dos2unix to... -
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... -
Sam Holden #2
Re: pass cmd line file glob to grep for readdir
On 8 Sep 2003 22:57:15 -0700, qanda <fumail@freeuk.com> wrote:
Why not use perl's glob function (perldoc -f glob)?>
> My question is how can I take a file glob on the command line and
> transform it into an expression for grep. I suppose this also implies
> we must prevent the shell from expanding by quoting the expression
> such as myscript *file*.ext"
--
Sam Holden
Sam Holden Guest
-
Eric J. Roode #3
Re: pass cmd line file glob to grep for readdir
[email]fumail@freeuk.com[/email] (qanda) wrote in news:62b4710f.0309082157.4c16ee32
@posting.google.com:
Have you considered using the xargs shell command?> Hi all
>
> I want to process lots of files (too many for the shell to expand on
--
Eric
$_ = reverse sort $ /. r , qw p ekca lre uJ reh
ts p , map $ _. $ " , qw e p h tona e and print
Eric J. Roode Guest
-
qanda #4
Re: pass cmd line file glob to grep for readdir
> Why not use perl's glob function (perldoc -f glob)?
Because it won't work, as perldoc says, it returns the filename
expansions from the shell, the underlying problem is because the shell
has a limit in the number of characters allowed in one line (it may be
big, maybe 1MB) but with thousands of files, each with 30 or 40
character filenames that soon runs out. I don't want the user to try
using find and/or xargs, I just want to call myscript file*.ext or
quoted as in myscript "file*.ext" if need be.
Thanks.
qanda Guest
-
Tad McClellan #5
Re: pass cmd line file glob to grep for readdir
Sam Holden <sholden@flexal.cs.usyd.edu.au> wrote:
> On 8 Sep 2003 22:57:15 -0700, qanda <fumail@freeuk.com> wrote:>>>
>> My question is how can I take a file glob on the command line and
>> transform it into an expression for grep. I suppose this also implies
>> we must prevent the shell from expanding by quoting the expression
>> such as myscript *file*.ext"
> Why not use perl's glob function (perldoc -f glob)?
This is a good idea if you have a perl version >= 5.6.0.
(otherwise the glob will fail because of the shell's limitations)
--
Tad McClellan SGML consulting
[email]tadmc@augustmail.com[/email] Perl programming
Fort Worth, Texas
Tad McClellan Guest
-
Tad McClellan #6
Re: pass cmd line file glob to grep for readdir
Eric J. Roode <REMOVEsdnCAPS@comcast.net> wrote:
> [email]fumail@freeuk.com[/email] (qanda) wrote in news:62b4710f.0309082157.4c16ee32
> @posting.google.com:
>>>> Hi all
>>
>> I want to process lots of files (too many for the shell to expand on
> Have you considered using the xargs shell command?
This is a good idea if you have perl version < 5.6.0.
--
Tad McClellan SGML consulting
[email]tadmc@augustmail.com[/email] Perl programming
Fort Worth, Texas
Tad McClellan Guest
-
Sam Holden #7
Re: pass cmd line file glob to grep for readdir
On 9 Sep 2003 05:53:29 -0700, qanda <fumail@freeuk.com> wrote:
Maybe you should use a perl from this century, since the text:>>> Why not use perl's glob function (perldoc -f glob)?
> Because it won't work, as perldoc says, it returns the filename
> expansions from the shell, the underlying problem is because the shell
> has a limit in the number of characters allowed in one line (it may be
> big, maybe 1MB) but with thousands of files, each with 30 or 40
> character filenames that soon runs out. I don't want the user to try
> using find and/or xargs, I just want to call myscript file*.ext or
> quoted as in myscript "file*.ext" if need be.
Beginning with v5.6.0, this operator is implemented using the
standard "File::Glob" extension. See File::Glob for details.
in the documentation seems to disagree with your claim.
It might also be worthwhile finding a non-broken shell.
; cd /dev
; echo * * * * * * * * * * * * * * * * * * * * * * * \
* * * * * * * * * * * * * * * * * * * * * * * \
* * * * * * * * * * * * * * * * * * * * * * * \
* * * * * * * * * * * * * * * * * * * * * * * \
| wc
1 128984 783012
; perl -le 'print join " ", <* * * * * * * * * * * * * * * * * * * * * * *'\
' * * * * * * * * * * * * * * * * * * * * * * *'\
' * * * * * * * * * * * * * * * * * * * * * * *'\
' * * * * * * * * * * * * * * * * * * * * * * *>' | wc
0 128984 783012
; /bin/echo * * * * * * * * * * * * * * * * * * * * * * * \
* * * * * * * * * * * * * * * * * * * * * * * \
* * * * * * * * * * * * * * * * * * * * * * * \
* * * * * * * * * * * * * * * * * * * * * * * \
| wc
bash: /bin/echo: Argument list too long
The limit is with the operating system, not the shell, so why should perl's
glob have any more difficulty than the shell's?
Have you actually tried it out? My 10 second test above seems to disagree
with your "it won't work" statement.
--
Sam Holden
Sam Holden Guest
-
Tad McClellan #8
Re: pass cmd line file glob to grep for readdir
qanda <fumail@freeuk.com> wrote:
>>> Why not use perl's glob function (perldoc -f glob)?
> Because it won't work, as perldoc says, it returns the filename
> expansions from the shell,
Only with old perls.
What perl version do you have?
--
Tad McClellan SGML consulting
[email]tadmc@augustmail.com[/email] Perl programming
Fort Worth, Texas
Tad McClellan Guest
-
qanda #9
Re: pass cmd line file glob to grep for readdir
Thanks guys and girls, I wasn't aware it had been improved in the new
versions; I'm limited (by customer) to using 5.005.
As for the argument limit, yes the underlying issue is with the OS, as
I understand it the limit is set by ARG_MAX in limits.h.
Would anyone be able to answer the (original) question for me,
certainly if using a newer version of Perl glob would be fine; however
I can't do that for this particular problem and the only overhead I
want for the user is to possibly quote the file glob so we avoid find
and/or xargs, etc.
Thanks again.
qanda Guest
-
qanda #10
Re: pass cmd line file glob to grep for readdir
Sorry for posting on top of my last reply, but I really do need help
with this one. I will be forever (well quite some time at least) in
your debt if you can help :)
qanda Guest



Reply With Quote

