SPUG: Is 'given' an expression? Will it be?
Dave Olszewski
cxreg at pobox.com
Thu Jan 27 11:18:22 PST 2011
You're thinking of 5.14
http://www.effectiveperlprogramming.com/blog/683
I'm not sure if it returns a value in perl 6, but that also has
gather/take which is a dynamically scoped version of the same concept.
It looks like TheDamian has implemented in for perl5 as well:
http://search.cpan.org/~dconway/Perl6-Gather-0.42/
Dave
On Thu, 27 Jan 2011, Michael R. Wolf wrote:
> 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
>
>
>
> _____________________________________________________________
> Seattle Perl Users Group Mailing List
> POST TO: spug-list at pm.org
> SUBSCRIPTION: http://mail.pm.org/mailman/listinfo/spug-list
> MEETINGS: 3rd Tuesdays
> WEB PAGE: http://seattleperl.org/
>
>
>
More information about the spug-list
mailing list