in reply to Globbing drives me nuts - some things seem counterintuitive

Imagine I have a directory with absolutely no files *.txt
> perl -e 'print "result: <",glob("*.txt"),">\n";' result: <x.txt>
That's a bug. And it's something I can't reproduce.

Abigail

Replies are listed 'Best First'.
Re: Re: Globbing drives me nuts - some things seem counterintuitive
by Sandy (Curate) on Apr 01, 2004 at 22:09 UTC
    Sorry Abigail

    If you look at all of the stuff, in between I made a file  dir >x.txt just to prove (to myself) that it actually worked when there was a file.

    What drives me nuts is it returns "xx.txt" if "xx.txt" was passed to the "glob" even if "xx.txt" does not exist.

      What drives me nuts is it returns "xx.txt" if "xx.txt" was passed to the "glob" even if "xx.txt" does not exist.
      While that can be frustrating if it doesn't DWIM, I can think of a use for it.
      foreach my $file_spec ( @ARGV ) { my @files = glob( $file_spec ); foreach my $file ( @files ) { if ( not(-e $file) and ( $file =~ /[.*]/ ) ) # change as appropriate { warn "Error: file $f doesn't exist," . " or wildcard didn't match, " unless -e $file; } } }
      You might want to know which wildcard didn't match.

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