in reply to Re: Pseudo-switch question
in thread Pseudo-switch question

Concering the correction - you could just append ->(). The null thing doesn't work if you get a key not contained in the hash, though. I'd do something like
my($favorite_color) = ''; # get some kind of input here my $action = { 'red' => sub { 'the color is red.' }, 'yellow' => sub { 'the color is yellow.' }, 'blue' => sub { 'the color is blue.' }, }->{$favourite_color} || sub { 'I do not know that color' }; print $action->();
You can arrange the same semantics in different ways, of course. I chose it like this since I was aiming to keep the "default case" together with the rest.

Makeshifts last the longest.