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

Re: [PBML] Re: Regex - repeating a pattern within two anchors?

Expand Messages
  • merlyn@stonehenge.com
    ... This is dangerous: hooyar66 $line =~ / (.+) /; because if it *doesn t* match, then: hooyar66 my $str = $1; the $1 there is the *previous* $1. Bad.
    Message 1 of 3 , Apr 1, 2007
    • 0 Attachment
      >>>>> "hooyar66" == hooyar66 <pcbcad@...> writes:

      This is dangerous:

      hooyar66> $line =~ /\"(.+)\"/;

      because if it *doesn't* match, then:

      hooyar66> my $str = $1;

      the $1 there is the *previous* $1. Bad. Very bad idea.

      NEVER use $1 except in a context where you have validated that the
      match has actually succeeded.

      --
      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.