in reply to Re: What I Most Recently Learned in Perl, But Should Have Already Known
in thread What I Most Recently Learned in Perl, But Should Have Already Known
Continuing the if-else statements problem, the idiom I like most is:
my $function = 'a'; my %functions = ( 'a' => sub { ... }, 'b' => sub { ... }, ); $functions{$function}->();
It's amazing how this replace an entire switch or if-else statements.
Igor 'izut' Sutton
your code, your rules.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: What I Most Recently Learned in Perl, But Should Have Already Known
by sfink (Deacon) on Aug 18, 2006 at 16:48 UTC | |
by izut (Chaplain) on Aug 18, 2006 at 20:43 UTC |