BrowserUk has asked for the wisdom of the Perl Monks concerning the following question:
I converting a peice of C source to Perl. The C has the following construct
switch(len) { case 11: c+=((unsigned int)k[10]<<24); case 10: c+=((unsigned int)k[9]<<16); case 9 : c+=((unsigned int)k[8]<<8); case 8 : b+=((unsigned int)k[7]<<24); case 7 : b+=((unsigned int)k[6]<<16); case 6 : b+=((unsigned int)k[5]<<8); case 5 : b+=k[4]; case 4 : a+=((unsigned int)k[3]<<24); case 3 : a+=((unsigned int)k[2]<<16); case 2 : a+=((unsigned int)k[1]<<8); case 1 : a+=k[0]; /* case 0: nothing left to add */ }
I've elected (for now) to translate this as
goto "LAST".$len; LAST11: $c+= $k[10] <<24; LAST10: $c+= $k[9] <<16; LAST9: $c+= $k[8] <<8; LAST8: $b+= $k[7] <<24; LAST7: $b+= $k[6] <<16; LAST6: $b+= $k[5] <<8; LAST5: $b+= $k[4]; LAST4: $a+= $k[3] <<24; LAST3: $a+= $k[2] <<16; LAST2: $a+= $k[1] <<8; LAST1: $a+= $k[0]; LAST0:
Any offers for a better translation?
Examine what is said, not who speaks.
The 7th Rule of perl club is -- pearl clubs are easily damaged. Use a diamond club instead.
Title edit by tye, see Eek! goto? instead
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Eek! goto?
by tachyon (Chancellor) on Feb 12, 2003 at 00:18 UTC | |
by BrowserUk (Patriarch) on Feb 12, 2003 at 00:37 UTC | |
by tachyon (Chancellor) on Feb 12, 2003 at 00:45 UTC | |
|
Re: Eek! goto?
by djantzen (Priest) on Feb 11, 2003 at 23:45 UTC | |
by BrowserUk (Patriarch) on Feb 12, 2003 at 00:10 UTC | |
by djantzen (Priest) on Feb 12, 2003 at 00:22 UTC | |
|
Re: Eek! goto?
by jdporter (Paladin) on Mar 24, 2003 at 06:58 UTC | |
by BrowserUk (Patriarch) on Mar 24, 2003 at 12:48 UTC | |
by jdporter (Paladin) on Mar 24, 2003 at 13:21 UTC | |
|
Re: Eek! goto?
by Aristotle (Chancellor) on Feb 19, 2003 at 12:32 UTC | |
by BrowserUk (Patriarch) on Feb 19, 2003 at 13:57 UTC | |
by Aristotle (Chancellor) on Feb 19, 2003 at 14:31 UTC | |
|
Re: Eek! goto?
by Juerd (Abbot) on Feb 11, 2003 at 23:46 UTC | |
by BrowserUk (Patriarch) on Feb 12, 2003 at 00:34 UTC | |
by shotgunefx (Parson) on Feb 12, 2003 at 15:34 UTC | |
by Juerd (Abbot) on Feb 12, 2003 at 18:57 UTC |