Loading ...
Sorry, an error occurred while loading the content.

Re: [PBML] question on glob behavior

Expand Messages
  • John Francini
    Sorry, that won t work. According to the Camel Book (Programming Perl): If you want to glob filenames that might contain whitespace, you ll need to use the
    Message 1 of 4 , Jul 3, 2007
    • 0 Attachment
      Sorry, that won't work.

      According to the Camel Book (Programming Perl):

      "If you want to glob filenames that might contain whitespace, you'll
      need to use the File::Glob module directly, since glob grandfathers
      the use of whitespace to separate multiple patterns such as <*.c
      *.h>. For details, see File::Glob in Chapter 32, "Standard Modules".

      "When you call open, Perl does not expand wildcards, including
      tildes. You need to glob the result first.

      open(MAILRC, "~/.mailrc") # WRONG: tilde is a shell thing
      or die "can't open ~/.mailrc: $!";

      open(MAILRC, (glob("~/.mailrc"))[0]) # expand tilde first
      or die "can't open ~/.mailrc: $!";


      Hope this helps!

      John


      At 8:41 -0400 7/3/07, Schelske, Steve K. wrote:
      >Active Perl/Win XP
      >
      >I ran into what I thought was strange behavior with a glob and was
      >hoping for an explanation.
      >
      >This first glob does what I expect - it populates the array with all of
      >the files in the globtest directory that start with test.
      >
      >@files = glob('c:/temp/globtest/test*');
      >print "@files\n";
      >
      >c:/temp/globtest/test .txt c:/temp/globtest/test 20070703082107.txt
      >c:/temp/glob
      >test/test 20070703082256.txt c:/temp/globtest/test20070703081959.txt
      >c:/temp/glo
      >btest/test20070703082010.txt
      >
      >When I put a space at the end of the string in this glob, @files gets
      >populated with the one file in globtest that matches (but not the file
      >file name, and not all of the files that match), but also with every
      >file in the current directory.
      >
      >@files = glob('c:/temp/globtest/test *');
      >print "@files\n";
      >
      >c:/temp/globtest/test acg_batch.pl acg_batch.pl.bak perl_env.pl
      >systest.pl test.
      >pl test.pl.bak test_ora.pl testarg.txt vpn.pl x.txt xrfwin.pl
      >xrfwin.pl.bak
      >
      >Can someone explain why this is happening? Is it really what I've asked
      >glob to do?
      >
      >[Non-text portions of this message have been removed]
      >
      >

      --
      John Francini, francini@...

      "The journey is more important than the destination -- that's part of life.
      If you only live for getting to the end, you're almost always disappointed."
      -- Donald Knuth

      [Non-text portions of this message have been removed]
    Your message has been successfully submitted and would be delivered to recipients shortly.