Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Out of Memory with File::Glob

by dvergin (Monsignor)
on Oct 28, 2003 at 05:25 UTC ( [id://302635]=perlquestion: print w/replies, xml ) Need Help??

dvergin has asked for the wisdom of the Perl Monks concerning the following question:

I'm running Perl 5.8.0 under Redhat 7.3. Here's the demo code:
#!/usr/bin/perl use warnings; use strict; use File::Glob ':glob'; print "Before first glob\n"; my @ary1 = glob('/*'); print "Before second glob\n"; my @ary2 = glob('/home/*'); print "Done\n";
And here's the result:
Before first glob
Before second glob
Out of memory!
If I comment out the line " use File::Glob ':glob';", it runs fine (but without File::Glob's handling of directories containing spaces in the full script from which this is derived).

If I comment out *either* glob(), it runs fine.

Why can't I invoke glob() twice while using File::Glob ':glob'? And what's the remedy?

------------------------------------------------------------
"Perl is a mess and that's good because the
problem space is also a mess.
" - Larry Wall

Replies are listed 'Best First'.
Re: Out of Memory with File::Glob
by pg (Canon) on Oct 28, 2003 at 05:59 UTC

    This is a known bug, not just redhat, I tried on windows, exactly the same problem.

    To handle spaces, just use bsd_glob. For example:

    use File::Glob ':glob'; use Data::Dumper; my $pattern = "C:/Program Files/*"; my @ary1 = bsd_glob("$pattern"); my @ary2 = bsd_glob("$pattern"); my @ary3 = bsd_glob("$pattern"); print Dumper(\@ary1);
      Confirmed. That works here, too. Thanks pg.
Re: Out of Memory with File::Glob
by Zaxo (Archbishop) on Oct 28, 2003 at 05:54 UTC

    I can replicate this in 5.6.1 i686-linux and get a little more error message,

    $ perl -Mwarnings -Mstrict -MFile::Glob=:glob -e'my @ary1 = glob q(/*) +; my @ary2 = glob q(/home/*)' Out of memory during "large" request for 1073745920 bytes, total sbrk( +) is 367464 bytes at /usr/lib/perl5/5.6.1/i686-linux/File/Glob.pm lin +e 127. $
    but it runs fine for me in 5.8.1 i686-linux-thread-multi.

    After Compline,
    Zaxo

Re: Out of Memory with File::Glob
by Art_XIV (Hermit) on Oct 28, 2003 at 14:37 UTC

    File::Find may provide you with an end-run around the problem, depending upon what it is you are trying to do.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://302635]
Approved by davido
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2024-03-28 15:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found