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

Re: [PBML] repeated use of grep

Expand Messages
  • merlyn@stonehenge.com
    ... Glenn Would this be a reasonable place to use eval -- say, wrap the two Glenn lines above in an eval block? like the following Glenn eval {
    Message 1 of 11 , Jun 12, 2007
      >>>>> "Glenn" == Glenn Becker <burningc@...> writes:

      >> This is really dangerous.... don't do this. Don't use $1 unless
      >> you've also checked that the match has succeeded.

      Glenn> Would this be a reasonable place to use "eval" -- say, wrap the two
      Glenn> lines above in an "eval" block? like the following

      Glenn> eval { /:\s+(.*tgz$)/;
      Glenn> push @packages, $1 };
      Glenn> print "No match occurred!\n:$@" if $@;

      No, it won't throw an exception if it doesn't match. Just follow the
      guidelines. Use it in a conditional if you *expect* it not to match
      sometimes. Use it with "or die" if you *never* expect it not to match.

      Glenn> Is the danger of using $1 that, if the match does not succeed, you are
      Glenn> accessing a "left-over" $1 from another match?

      Yes. Or just garbage.... after all, even if $1 was undef on a non-match, your
      code would be wrong, because it would push undef into @packages, still ruining
      the algorithm.

      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.