in reply to (duplicate) Eek! goto?

Yukfoo source, what is it for? This is still pretty ugly, possibly easier to understand (but that is arguable), and has the same fall through behaviour. You could map to a string and use eval but that is even more evil than goto....

my %dispatch = ( 11 => sub{ $c+=$k[10]<<24 }, 10 => sub{ $c+=$k[9] <<16 }, 9 => sub{ $c+=$k[8] <<8 }, 8 => sub{ $b+=$k[7] <<24 }, 7 => sub{ $b+=$k[6] <<16 }, 6 => sub{ $b+=$k[5] <<8 }, 5 => sub{ $b+=$k[4] }, 4 => sub{ $a+=$k[3] <<24 }, 3 => sub{ $a+=$k[2] <<16 }, 2 => sub{ $a+=$k[1] <<8 }, 1 => sub{ $a+=$k[0] } ); &{$dispatch{$_}} for reverse 1..$len;

cheers

tachyon

s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Replies are listed 'Best First'.
Re: Re: Eek! goto?
by BrowserUk (Patriarch) on Feb 12, 2003 at 00:37 UTC

    Its a hashing algorithm.

    I like the lateral thinking of the reverse, but unless I make $a,$b,$c and @k globals, the additional cost of parameters is a pain.


    Examine what is said, not who speaks.

    The 7th Rule of perl club is -- pearl clubs are easily damaged. Use a diamond club instead.

      ??? - The vars don't need to be any more global than with the goto solution. The reverse 1..10 comes in handy seeing you can't have 10..1 which would be much prettier.

      { my $a; my $var = sub{ $a = 'OK?' }; &$var; print $a }

      cheers

      tachyon

      s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print