note
LanX
this thread is bloated b/c you didn't make clear what your real problem is and where your priorities are.<P><P>
if its only about translating a number, than using a hash is by far the best solution<P><P>
<c>
use strict;
use warnings;
my %trans = (1 => "One", 2 => "Two", 3 => "Three");
my $var = '2.123.45.6';
if ( $var =~ /^(\d)\./ ) {
print "$var starts with $trans{$1}";
} else {
print "$var malformed";
}
</c><P><P>
Now since this became a general discussion of "switch", for completeness TIMTOWTDI:<P><P>
<c>
use strict;
use warnings;
my $i;
for my $case (1..4) {
eval { goto "_$case" } or
$i = "Other"; next;
_1: $i = "One" ; next;
_2: $i = "Two" ; next;
_3: $i = "Three"; next;
} continue {
print "$case is $i\n";
}
</c><P><P>
Hashes with dispatch tables (slow sub calls) and if-elsif-chains (slow linear testing) shouldn't be as fast as this approach.
<P><P>
<!-- Node text goes above. Div tags should contain sig only -->
<div class="pmsig"><div class="pmsig-708738">
<p>Cheers Rolf
<p> <small>( addicted to the Perl Programming Language) </small>
</div></div>
1078449
1078449