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

Tim Maher tim at consultix-inc.com
Tue Feb 13 14:04:47 PST 2007


On Tue, Feb 13, 2007 at 01:33:22PM -0800, Yitzchak Scott-Thoennes wrote:
> Tim Maher wrote:
> >> 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.

Aargh! I've been spending a lot of time working on systems with "classic"
Perl versions recently, so I forgot that we have auto-local scoping of
special variables now--which is a mixed blessing, with respect to 
backwards compatability of legacy code.

But I've been waiting for the day when I could remove all the
	local $/; # defend against module's trashing
lines preceding my
	File::Find::find()
calls! 8-}

Yitzchak, can you tell us when dynamic scoping of special vars
became automatic, and possibly point us to the relevant Changes file?

> Please don't use Switch in real code...
Sounds like sage advice!

TIA,
-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