SPUG: Switch's "case" matching doesn't set $1 !
sthoenna at efn.org
Tue Feb 13 13:33:22 PST 2007
Tim Maher wrote:
> On Tue, Feb 13, 2007 at 11:13:13AM -0800, Eric Wilhelm wrote:
>> # from Tim Maher
>> # on Tuesday 13 February 2007 10:48 am:
>> > What's more, the docs characterize the
>> >"case /re/" syntax as "match if $s =~ /$c/", suggesting that any
>> >regex valid in a real matching operator should be usable.
>> Try dumping the filtered source.
>> perl -MO=Deparse script
>> There, you'll see that it is indeed the "if/elsif/elsif/else" lexical
>> structure that you might expect from the input structure, but rather
>> than doing "$_ =~ m/.../" in the if(), it ships the regexp off to the
>> case() function
> ... which, AFAICT (see below), then does the "$_ =~ m/.../"
but in a different scope, and $1 is automatically dynamically scoped.
The scope in which the match occurs is left before your attempt to
Please don't use Switch in real code...
More information about the spug-list