in reply to Re: Given When Syntax
in thread Given When Syntax
> use the dark arts mate
maybe a misunderstanding, but I thought black is supposed to be beautiful not ugly! :-b
sub switch ($$); for my $var (1..4) { my $i; switch $var => { 1 => sub { $i = "One"}, 2 => sub { $i = "Two"}, 3 => sub { $i = "Three"}, '' => sub { $i = "Other"}, }; print "$var is $i\n"; } sub switch ($$) { my ($case, $href) =@_; if ( exists $href->{$case} ) { $href->{$case}->(); } else { $href->{''}->(); } }
Cheers Rolf
( addicted to the Perl Programming Language)
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: Given When Syntax
by Lennotoecom (Pilgrim) on Mar 15, 2014 at 20:05 UTC | |
by LanX (Saint) on Mar 15, 2014 at 20:18 UTC | |
by Lennotoecom (Pilgrim) on Mar 15, 2014 at 20:24 UTC |
In Section
Seekers of Perl Wisdom