SPUG: Is 'given' an expression? Will it be?
Michael R. Wolf
MichaelRWolf at att.net
Thu Jan 27 10:46:45 PST 2011
I seem to remember, but can't find references to given having a return value as an expression, not merely being flow control.
Am I making up this feature, mis-implementing it, or thinking future (Perl 5.12+, Perl6)?
@days = qw(Monday Tuesday Wednesday ...);
my $day = $days[random @days];
my $soup = given ($day) {
when ('Monday') { 'Barley' }
when (qr/^T/) { 'Tomatoe' }
when ([qw(Wednesday Sunday)]) {'Chilie'}
default { 'Leftovers' }
};
Of course, I can put the assignment in *each* 'when', but that's repeating myself, and I like to follow principle of DRY - Don't Repeat Yourself.
--
Michael R. Wolf
All mammals learn by playing!
MichaelRWolf at att.net
More information about the spug-list
mailing list