FAQ
This is a bug report for perl from [email protected]
generated with the help of perlbug 1.33 running under perl v5.6.1.


-----------------------------------------------------------------
[Please enter your report here]

This is a pod patch and a bug report.

Documentation update:

*** perlfunc.pod.orig Thu Jan 4 20:34:28 2001
--- perlfunc.pod Wed Mar 28 21:03:29 2001
***************
*** 1985,1990 ****
--- 1985,1998 ----
Beginning with v5.6.0, this operator is implemented using the standard
C<File::Glob> extension. See L<File::Glob> for details.

+ In scalar context, returns one name at a time. Call glob with the
+ same arguments repeatedly to get them all.
+
+ perl -le 'while ($_ = glob "/tmp/*") {print}'
+
+ Note: glob() in scalar context is not recursive. Use C<File::Find>
+ to process subdirectories.
+
=item gmtime EXPR

Converts a time as returned by the time function to a 8-element list

---------------------------------------

Bug report:

When called in scalar context, glob() returns one name at a time. This
works OK if glob() is called repeated with the same argument over and
over until the cached list of matches is exhausted.

But if glob() is called with a different argument before the cache is
emptied, the partial results are not saved. Recursive descent down the
directory tree is OK, but an infinite loop occurs on the way back up.

glob() should either handle recursive calls in scalar context, or it
should die() cleanly on the way back up.

The enclose program exhibits the error when run with a nonzero command
line argument (such as "9").

#!/bin/perl
print "Testing use of repeated calls to glob() in scalar context\n";
# Should produce results similar to grep(!/^\./,readdir()).

$start = "/etc/lp"; # A not-very deep dir tree on Solaris-6
$max = @ARGV ? shift : 0; # Number of directories to do in bug mode
print $max ? "Recursive mode: expect failure\n" : "Works: push results\n";

$count = $depth = 0;
do_dir("$start/");
print "done\n";

sub do_dir {
my $dir = shift;
my $prefix = " " x ++$depth;
my @todo;
my $files = $dir . "*";
print "$prefix Looking for $files\n";
die "Too many directories processed: $max" if $max && ++$count > $max;
while ($name = glob $files) { # Repeated calls in scalar context
if (-d $name) {
print "$prefix $name is a directory\n";
$max ? do_dir("$name/") : push @todo,"$name/";
} else {
print "$prefix $name is not a directory\n";
}
}
foreach $dir (@todo) { # If $max set, do dirs after loop
do_dir($dir);
}
print "$prefix End of $files\n";
--$depth;
}


[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags:
category=core
severity=medium
---
Site configuration information for perl v5.6.1:

Configured by jms at Thu Jan 4 15:37:43 PST 2001.

Summary of my perl5 (revision 5.0 version 6 subversion 1) configuration:
Platform:
osname=solaris, osvers=2.6, archname=sun4-solaris
uname='sunos centauri 5.6 generic_105181-07 sun4u sparc sunw,ultra-2 '
config_args='-de'
hint=recommended, useposix=true, d_sigaction=define
usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef
useperlio=undef d_sfio=undef uselargefiles=define usesocks=undef
use64bitint=undef use64bitall=undef uselongdouble=undef
Compiler:
cc='gcc', ccflags ='-fno-strict-aliasing -I/usr/local/include -I/opt/local/include -I/opt/gnu/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
optimize='-O',
cppflags='-fno-strict-aliasing -I/usr/local/include -I/opt/local/include -I/opt/gnu/include'
ccversion='', gccversion='2.95.2 19991024 (release)', gccosandvers='solaris2.6'
intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=4321
d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
alignbytes=8, usemymalloc=y, prototype=define
Linker and Libraries:
ld='gcc', ldflags =' -L/usr/local/lib -L/opt/local/lib -L/opt/gnu/lib '
libpth=/usr/local/lib /opt/local/lib /opt/gnu/lib /lib /usr/lib /usr/ccs/lib
libs=-lsocket -lnsl -lgdbm -ldb -ldl -lm -lc -lcrypt -lsec
perllibs=-lsocket -lnsl -ldl -lm -lc -lcrypt -lsec
libc=/lib/libc.so, so=so, useshrplib=false, libperl=libperl.a
Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags=' '
cccdlflags='-fPIC', lddlflags='-G -L/usr/local/lib -L/opt/local/lib -L/opt/gnu/lib'

Locally applied patches:
v5.6.1-TRIAL1

---
@INC for perl v5.6.1:
/usr/local/lib/perl5/5.6.1/sun4-solaris
/usr/local/lib/perl5/5.6.1
/usr/local/lib/perl5/site_perl/5.6.1/sun4-solaris
/usr/local/lib/perl5/site_perl/5.6.1
/usr/local/lib/perl5/site_perl/5.6.0/sun4-solaris
/usr/local/lib/perl5/site_perl/5.6.0
/usr/local/lib/perl5/site_perl/5.005/sun4-solaris
/usr/local/lib/perl5/site_perl/5.005
/usr/local/lib/perl5/site_perl
.

---
Environment for perl v5.6.1:
HOME=/centauri/home/mci/jms
LANG (unset)
LANGUAGE (unset)
LC_COLLATE=en_US
LD_LIBRARY_PATH (unset)
LOGDIR (unset)
PATH=/centauri/home/mci/jms/bin:/centauri/home/mci/jms/bin.sunos5:/centauri/home/mci/jms/bin.sparc:/usr/openwin/bin:/usr/newsprint/bin:/usr/X11R6/bin:/usr/X11R5/bin:/opt/SUNWspro/bin:/usr/ccs/bin:/usr/ucb:/usr/bin:/usr/sbin:/sbin:/usr/proc/bin:/usr/local/bin:/usr/local/etc:/usr/local/admin:/opt/gnu/bin:/usr/local/samba/bin:/usr/tym:/usr/shosts:/mww/mybin
PERL_BADLANG (unset)
SHELL=/bin/tcsh

Search Discussions

  • Benjamin Sugars at Mar 29, 2001 at 6:34 pm

    On Wed, 28 Mar 2001, Joe Smith wrote:

    glob() should either handle recursive calls in scalar context, or it
    should die() cleanly on the way back up.
    The problem is that the pattern alone isn't sufficient to maintain state.
    In your example, successive patterns were unique, but this won't always be
    the case. The calling environment needs to provide some context to glob
    so that it can distinguish between different calls even if the pattern is
    the same.

    Interestingly enough, File::Find::csh_glob() is all set up to accept a
    second argument for context, but the core only gives csh_glob a unique
    value for this argument for each glob in the op tree, not for each time
    glob is called.

    To get the effect you want, you could call csh_glob yourself passing it a
    (unique) second argument for each level of recursion, but as you yourself
    said File::Find is probably a better tool.

    Cheers,
    -Ben

    PS. "die() cleanly" is an oxymoron.

    --
    signer: can't create ~/.sig: Not a directory
  • Benjamin Sugars at Mar 29, 2001 at 6:38 pm

    On Thu, 29 Mar 2001, I, Benjamin Sugars, wrote:

    Interestingly enough, File::Find::csh_glob() is all set up to accept a
    Sorry, I mean to say File::Glob::csh_glob().
    second argument for context, but the core only gives csh_glob a unique
    value for this argument for each glob in the op tree, not for each time
    glob is called.
    Cheers,
    -Ben

    --
    signer: can't create ~/.sig: Software caused connection abort

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupperl5-porters @
categoriesperl
postedMar 29, '01 at 5:28a
activeMar 29, '01 at 6:38p
posts3
users2
websiteperl.org

2 users in discussion

Benjamin Sugars: 2 posts Joe Smith: 1 post

People

Translate

site design / logo © 2023 Grokbase