http://www.perlmonks.org?node_id=999146


in reply to glob quietly fails

What are you expecting the first code example to do?

As it is, it creates an array of 2 strings each 129 characters long and then glob returns them. Which is working just fine for me ;)

UPDATE : Ah! your calling glob in scalar context! try a list context instead.

for my $g (glob(...) ) { }

Replies are listed 'Best First'.
Re^2: glob quietly fails
by remiah (Hermit) on Oct 15, 2012 at 20:06 UTC

    Hello RichardK.

    glob fails silently as QM saids with my perl. How does this code say with your platform?

    for (my $q =1; $q < 10000; $q++){ my @x = ( 'A' x $q, 'B' x $q ); my $glob = '{' . join(',', @x) . '}'; my $g = join(',', glob($glob)); if (length $g == 0){ print "fail silently, q=$q\n"; last; } }
    Mine stops saying
    fail silently, q=511
    
    perl -v
    This is perl 5, version 12, subversion 2 (v5.12.2) built for i386-freebsd-thread-multi-64int
    
    regards.

Re^2: glob quietly fails
by Anonymous Monk on Oct 15, 2012 at 18:28 UTC

    UPDATE : Ah! your calling glob in scalar context! try a list context instead.

    Both are supposed to work

Re^2: glob quietly fails
by QM (Parson) on Oct 16, 2012 at 12:24 UTC
    As remiah and Anonymous Monk have stated, I expected while and for to behave the same way, and they do for me, on Strawberry Perl v5.16.1:
    #!/usr/env/perl use strict; use warnings; my $q = (shift or 129); # 128 is the largest working value my @x = ( 'A' x $q, 'B' x $q ); my $glob = '{' . join(',', @x) . '}'; while (my $g = glob($glob)) { print "while: $g\n"; } for my $g ( glob( $glob ) ) { print "for: $g\n"; } __EOF__ ################# # result: # while: for:

    Running this with a command line argument of 128 gives the expected output of 2 very long strings for while and 2 for for.

    -QM
    --
    Quantum Mechanics: The dreams stuff is made of