$k is not manipulated during the course of that block, and all operations are additions, with which order does not matter. So you could reverse the order of operations and bail early from the block upon a counter reaching $len, rather than skip the first 11-$len instructions.
{ last if $len == 0; $a+= $k[0]; last if $len == 1; $a+= $k[1] <<8; last if $len == 2; $a+= $k[2] <<16; last if $len == 3; $a+= $k[3] <<24; last if $len == 4; $b+= $k[4]; last if $len == 5; $b+= $k[5] <<8; last if $len == 6; $b+= $k[6] <<16; last if $len == 7; $b+= $k[7] <<24; last if $len == 8; $c+= $k[8] <<8; last if $len == 9; $c+= $k[9] <<16; last if $len == 10; $c+= $k[10] <<24; }
Admittedly very redundant and not very graceful. Let's look at this another way: you have a basically data driven design here: the target and shift factor depends on the index. So not write it that way?
my @targ_shift = ( [ \$a, 0 ], [ \$a, 8 ], [ \$a, 16 ], [ \$a, 24 ], [ \$b, 0 ], [ \$b, 8 ], [ \$b, 16 ], [ \$b, 24 ], [ \$c, 8 ], [ \$c, 16 ], [ \$c, 24 ], ); for my $idx (0 .. $len-1) { my ($targ, $shift) = @{$targ_shift[$idx]}; $$targ += $k[$idx] << $shift; }
or maybe
{ my @targ_shift = ( \$a, 0, \$a, 8, \$a, 16, \$a, 24, \$b, 0, \$b, 8, \$b, 16, \$b, 24, \$c, 8, \$c, 16, \$c, 24, ); for (0 .. $len-1) { my ($targ, $shift) = splice @targ_shift, 0, 2; $$targ += $k[$_] << $shift; } }
"Capture regularities in code, irregularities in data", the koan of the senior programmer as merlyn so aptly put it.

Makeshifts last the longest.


In reply to Re: Eek! goto? by Aristotle
in thread (duplicate) Eek! goto? by BrowserUk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.