On Dec 16, 2:56 am, practicalp...@gmail.com (practicalperl) wrote:
> This has been confused me:
>
> [an...@localhost tmp]$ ls
> [an...@localhost tmp]$ perl -le'print glob("foo.3")'
> foo.3
>
> there is nothing in the tmp directory.
> but why glob("foo.3") returns the string?
>
> $ perl -v
>
> This is perl, v5.8.8 built for i686-linux
>

There weren't any  matches with files and no wildcards
in the glob pattern so the pattern itself is returned *.  If
there had been a wildcard in the pattern, then nothing
would have been returned.

perl -E "say glob('foo.3')"   <--- returns foo.3 *
perl -E "say glob('foo?3)"   <--- doesn't return anything

   *  You'd have to use bsd_glob in order to  not return
       the pattern if no files match, eg:
              use File::Glob ':glob';
              say bsd_glob('foo.3',GLOB_ERR);

      Otherwise, if there had been a file "foo.3" with an
      actual '.' in the filename, glob('foo.3') would also
      return that filename.

Perl uses File::Glob for globbing since 5.6.1 and  only
these metacharacters are recognized:

      \       Quote the next metacharacter
      []      Character class
      {}      Multiple pattern
      *       Match any string of characters
      ?       Match any single character
      ~       User name home directory

For more detail: perldoc File::Glob

Perhaps, you were thinking '.' was also a glob wildcard
as it  would be in a regex pattern...

--
Charles DeRykus


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to