in reply to Re^5: Error: Use of uninitialized value $item in concatenation (.) or string at...
in thread Error: Use of uninitialized value $item in concatenation (.) or string at...

You guys are great. I'll try testing my own ideas before coming here next time....

Basically, $1 and $2 take the value of inside the parentheses() of the last successful match (ie. the match is true). If there are no parentheses, they take the value of undef. If there is no match they don't get overwritten ...

Edit credit: AnomalousMonk and ig (not sure if I took the right steps here, can I just delete mine and rely on AnomalousMonk 's?).

Thanks a lot!
  • Comment on Re^6: Error: Use of uninitialized value $item in concatenation (.) or string at...

Replies are listed 'Best First'.
Re^7: Error: Use of uninitialized value $item in concatenation (.) or string at...
by AnomalousMonk (Archbishop) on Jun 12, 2011 at 06:43 UTC

    The capture variables ($1 $2 etc.) are set to the contents of their corresponding capture groups if there is a match; if there is no corresponding capture group, the capture variable is set to undef. If there is no match, the capture variable is uncanged.

Re^7: Error: Use of uninitialized value $item in concatenation (.) or string at...
by ig (Vicar) on Jun 13, 2011 at 10:26 UTC
    Basically, $1 and $2 only become 'undef'-ed when there is a un*successful* match.

    I'm not sure what you mean by "un*successful*", but it is likely to be (mis-)understood to mean something that is incorrect.

    AnomalousMonk has told you correctly. To emphasize where I think you may have gone wrong (or at least easily misunderstood as wrong) I might rewrite what you wrote as:

    Basically, $1 and $2 only become 'undef'-ed when there is a successful match and the matching expressions do not include any bracketing constructs "(...)" containing expressions that matched .

    That's not an elegant statement, and it may be more confusing than helpful, but it avoids the suggestion that an unsuccessful match might change the match variables ($1, $2, etc.).