in reply to Re: Flag variables
in thread Flag variables
What this code is doing is building a delayed action dispatch table. Whenever you need to look a variable up in an array, you should consider using a hash. That is exactly their forte.
my %lookup = ( foo=>\&fooaction, bar=>\&baraction, qux=>\&quxaction ); if (exists $lookup{$var}) { $lookup{$var}->(); } else { #do the default or exception handling here. }
It cleaner and clearer to read, uses loads less variables, is much easier to maintain and extend and more efficient to boot.
If brevity is compatible with your mindset, then the if/else can become
&{ $lookup{$var} || $default_subref }->( parms );
Examine what is said, not who speaks.
1) When a distinguished but elderly scientist states that something is possible, he is almost certainly right. When he states that something is impossible, he is very probably wrong.
2) The only way of discovering the limits of the possible is to venture a little way past them into the impossible
3) Any sufficiently advanced technology is indistinguishable from magic.
Arthur C. Clarke.
2) The only way of discovering the limits of the possible is to venture a little way past them into the impossible
3) Any sufficiently advanced technology is indistinguishable from magic.
Arthur C. Clarke.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Re: Flag variables
by KPeter0314 (Deacon) on Mar 03, 2003 at 19:58 UTC | |
by BrowserUk (Patriarch) on Mar 03, 2003 at 21:05 UTC |
In Section
Seekers of Perl Wisdom