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

Michael R. Wolf MichaelRWolf at att.net
Wed Feb 14 05:13:01 PST 2007


When I found this out, I freaked, too!  I guess I shouldn't have been so
surprised.  While at the Chicago hackathon in October, I was having a side
conversation with someone trying to decide whether to 'use Switch' or not,
so I interrupted the room to take a 10 second instant-poll.  The consensus
was "no"!  I was surprised by the answer, but listened to the collected
wisdom.   But then I forgot, and bumped into the bug a few months later.

(BTW: this "instant polling" was an interesting benefit of being in a room
with lots of experienced folks at the hackathon.  There's nothing like
instant feedback.  XP - extreme programming -> extreme feedback velocity.
And it happened *ALL OVER* the place at the hackathon.  During the Saturday
evening "status report", quite a few folks commented on how fast
conversations could take place face-to-face, and across-the-room when so
many of the concerned folks shared space.)

Here's the bug I submitted a few weeks ago.  There's been no action on it
since I submitted it.  I guess the anticipated fix-date is Perl6.

  http://rt.cpan.org/Public/Bug/Display.html?id=24027

Here's the code frag I submitted with the bug.  Feel free to add yours.

#! /usr/bin/perl

use warnings;
use Switch;

$data = 'catch 22';

switch ($data) {
    case qr/catch (\d+)/ {
	print "I know my gross situation: $data\n";
	print "My parsed situation is unknown: $1\n";
	warn 'Matched, but not captured' unless defined $1;
    }
    else {
	warn "$data is unrecognized\n";
    }
}


-- 
Michael R. Wolf
    All mammals learn by playing!
        MichaelRWolf at att.net






More information about the spug-list mailing list