Is there still unpredictable behavior with glob () in perl?

I found this piece of wisdom in PerlFaq listed on the chat forum since 2000.

Is there a leak / error in glob ()?

Due to the current implementation of some operating systems, when you use the glob () function or its angle bracket alias in a scalar context, you can cause leaks and / or unpredictable behavior. It is better therefore to use glob () only in the context of the list.

I read that this problem was fixed in Perl 5.6, but later I heard a report that it still occurs in 5.10.1

Has anyone had experience of recent issues and where would be the best place to find a definitive answer to this?

[Later ..] The latest PerlFAQ says:

5.18: Is there a leak / error in glob ()?

(contributed by brian d foy)

Starting with Perl 5.6.0, "glob" is implemented internally, rather than relying on an external resource. Thus, memory problems with "glob" are not a problem in modern perls.

=====

Finally: The reported problem was related to the misuse of glob, using it in a loop after it already provided all the matching elements. There were no problems with this.

+7
source share
2 answers

Using Luke Source and Commit History

http://perl5.git.perl.org/perl.git/history/HEAD:/ext/File-Glob

update: although this long deprecated perlfaq5 element was at 5.14 , it disappeared in the last

+5
source

I just tested Debian Wheezy with Perl 5.14.2 .

Scalar Context - Failure Failure

sub test { my $dir = shift; my $oldDir = cwd(); chdir($dir) or die("Could not chdir() : $!"); my $firstEntry = glob('*'); print "$firstEntry\n"; chdir($oldDir) or die("Could not chdir() : $!"); } # /tmp/test1 (contains file1 and file2) test('/tmp/test1); # Display file1 which is expected # /tmp/test2 (contains file3 and file4) test('/tmp/test2'); # Display file2 which is not expected 

List of contexts (works as expected)

 sub test { my $dir = shift; my $oldDir = cwd(); chdir($dir) or die("Could not chdir() : $!"); (my $firstEntry) = glob('*'); print "$firstEntry\n"; chdir($oldDir) or die("Could not chdir() : $!"); } # /tmp/test1 (contains file1 and file2) test('/tmp/test1); # Display file1 which is expected # /tmp/test2 (contains file3 and file4) test('/tmp/test2'); # Display file3 which is expected 

To return here, glob buffer not reset, even if we are not in the call zone.

With perl 5.22-1, both cases work as expected (scalar context).

+1
source

All Articles