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

Re: [PBML] Checking existence of multiple files

Expand Messages
  • flw
    Thank you very much! Sorry for my previous message.
    Message 1 of 8 , May 26, 2006
    • 0 Attachment
      Thank you very much!
      Sorry for my previous message.

      26 May 2006 05:51:53 -0700, Randal L. Schwartz <merlyn@...>:
      > >>>>> "flw" == flw <su2admin@...> writes:
      >
      > flw> Try this please:
      > flw> print "exist\n" if <Report*.OUT>;
      >
      > This uses glob in a scalar context and will work only every other time.
      > (Or fail every N times if you have N-1 files.)
      >
      > For example, consider:
      >
      > for (1..10) {
      > print "on time #$_, /etc/passwd ",
      > (-e </etc/passwd> ? "exists" : "does not exist"),
      > "\n";
      > }
      >
      > on time #1, /etc/passwd exists
      > on time #2, /etc/passwd does not exist
      > on time #3, /etc/passwd exists
      > on time #4, /etc/passwd does not exist
      > on time #5, /etc/passwd exists
      > on time #6, /etc/passwd does not exist
      > on time #7, /etc/passwd exists
      > on time #8, /etc/passwd does not exist
      > on time #9, /etc/passwd exists
      > on time #10, /etc/passwd does not exist
      >
      > (If you're on windows, substitute some file that you know is there.)
      >
      > The reason is that you're using a "scalar glob", which remembers
      > what it's told you so far, and the next time hands you the "next"
      > result, including an undef when you've gone through the entire list,
      > after which it resets. So, what it's returning is:
      >
      > "/etc/passwd", undef, "/etc/passwd", undef, ...
      >
      > Moral of the story: DON'T USE SCALAR GLOB, unless you're really
      > aware of what's happening.
      >
      > --
      > Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
      > <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
      > Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
      > See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
      >
    Your message has been successfully submitted and would be delivered to recipients shortly.