$y could be passed as a reference to avoid the string copy further reduce the disadvantage, particularly for large strings.
my %dispatch=( A=>sub { split(/!/,$$_[0]); }, ... ); sub dispatch { my $x=$letters[random($nLetters)]; my $y='xyzzy!' x random(1000); if (exists $dispatch{$x}) { $dispatch{$x}->(\$y); } else { warn "Huh?"; } }
On the other hand, maybe the parameter string isn't copied when the function references $_[0] directly?
In reply to Re^2: elsif chain vs. dispatch
by ruzam
in thread elsif chain vs. dispatch
by sflitman
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |