SPUG: Switch's "case" matching doesn't set $1 !

Tim Maher tim at consultix-inc.com
Tue Feb 13 18:45:20 PST 2007


On Tue, Feb 13, 2007 at 01:50:44PM -0800, Eric Wilhelm wrote:
> # from Tim Maher
> # on Tuesday 13 February 2007 11:56 am:
> 
> >To produce the effect I'm expecting, it's not necessary for the
> >match to be executed within the scope of the user's code--just
> >for the match to be left in $1--which, as part of the package
> >"main", is always in scope.
> 
> from perlre: "The numbered match variables ($1, $2, $3, etc.) and the 
> related punctuation set ($+, $&, $`, $', and $^N) are all dynamically 
> scoped until the end of the enclosing block or until the next 
> successful match, whichever comes first."

Right you are; I had forgotten about how that works, in part because I
hadn't done any programming that would have reminded me of it
recently. That's why I write such detailed notes for the student
manuals I use in my training courses! 8-}

-Tim
*-------------------------------------------------------------------*
|  Tim Maher, PhD  (206) 781-UNIX   http://www.consultix-inc.com    |
|  tim at ( Consultix-Inc, TeachMePerl, or TeachMeUnix ) dot Com    |
| Classes: 2/28: Basic Perl; 3/12: Basic UNIX/Linux; 3/16: Min Perl |
*-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-*
|  * "Minimal Perl" book rates 4.8 out of 5 stars at Amazon.com! *  |
| > Download chapters, read reviews, and order at MinimalPerl.com < |
*-------------------------------------------------------------------*


More information about the spug-list mailing list