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

Yitzchak Scott-Thoennes sthoenna at efn.org
Tue Feb 13 14:43:16 PST 2007

Tim Maher wrote:
> 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?

Um, it's not all special variables, just the regex ones.  A successful
match basically does the equivalent of local() on them.  It's been than
way as long as I remember...

Tye just verified for me that it's the same on perl4, and he remembers
perl3 being the same also.

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

But look forward to "given" in 5.10.

More information about the spug-list mailing list