in reply to Scope of regular expression variables
So, your $1 is "stomped" within the local scope of the enclosing braces. To elaborate:The variables $1, $2, $3 ... are automatically localized, and their sc +ope extends to the end of the enclosing block or eval string, or to t +he next successful pattern match, whichever comes first.
Update: See merlyn's clarification below. Seems either (a) I didn't understand the book correctly, or (b) he (or Larry or Tom) should've written it clearer. ;-)if ($_ =~ /ORG\:(.+)/) { # $1 in scope A if ($1 =~ /^(.+)\;(.+)\;(.+)$/) { # $1 now in scope B $card{'org'}=$1; $card{'div'}=$2; $card{'dept'}=$3; } # $1 now in scope A again elsif ($1 =~ /^\;(.+)\;(.+)$/) { # $1 now in scope C
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: Re: Scope of regular expression variables
by merlyn (Sage) on Aug 29, 2000 at 23:21 UTC | |
by takshaka (Friar) on Aug 30, 2000 at 02:35 UTC | |
by Carl-Joseph (Scribe) on Aug 30, 2000 at 03:47 UTC | |
by chromatic (Archbishop) on Sep 16, 2000 at 02:15 UTC |