SPUG: Switch's "case" matching doesn't set $1 !
Eric Wilhelm
scratchcomputing at gmail.com
Tue Feb 13 11:13:13 PST 2007
# from Tim Maher
# on Tuesday 13 February 2007 10:48 am:
>A perusal of the module's documentation and code didn't reveal any
>obvious explanation. 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. Ah, the logic of "what sort of match is this?" is in
case(), probably to defer it until runtime.
Had it been implemented as a DSL of prototyped functions (sub case ($&)
{...}, then the capture might work because your code would get executed
within scope of the match.
--Eric
--
Like a lot of people, I was mathematically abused as a child.
--Paul Graham
---------------------------------------------------
http://scratchcomputing.com
---------------------------------------------------
More information about the spug-list
mailing list