Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re**3: Eek! goto?

by belg4mit (Prior)
on Feb 12, 2003 at 03:21 UTC ( [id://234600]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Eek! goto?
in thread Eek! goto?

Actually no, it was me just not paying attention. You could always do
$H{('a'x4,'b'x4,'c'x3)[$len]} += $k[$len -1] << (8* (($len>8?$len:$len +-1)%4)); #OR no code change++ but symbolic-- ${('a'x4,'b'x4,'c'x3)[$len]} += $k[$len -1] << (8* (($len>8?$len:$len- +1)%4));

--
I'm not belgian but I play one on TV.

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

    I've tried to make this work. I added the implied while loop and put brackets around the 'a' etc. to make it generate lists not strings, but I still can get it to produce the same results as the original. Can you see what I missed?

    sub belg4mit { my %H; my ($len, @k) = @_; my ($a,$b,$c) = (0)x3; while($len--) { $H{(('a')x4,('b')x4,('c')x3)[$len]} += $k[$len -1] << (8* ( ($len > 8 ? $len : $len - 1 )%4 ) +); } return ($H{a}||0)+($H{b}||0)+($H{c}||0); }

    Examine what is said, not who speaks.

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

      while($len){ $H{(('a')x4,('b')x4,('c')x3)[--$len]} += $k[$len] << (8* ( ($len > 7 ? $len +1 : $len)%4 ) ); }
      This seems to match the output of pfaut's code. If benchmarking you could eek out some more throughput by storing the hash key indexes in an array (as opposed to forcing three x per iteration of the loop.

      --
      I'm not belgian but I play one on TV.

        Might be a bit faster if you throw out the hash and use an array. BTW, I think one of BrowserUK's later posts added back the originally missing low byte of $c so the check for $len > 7 can go, too.

        while ($len--) { $H[int($len/4)] += $k[$len] << (8 * ($len % 4)); }
        --- print map { my ($m)=1<<hex($_)&11?' ':''; $m.=substr('AHJPacehklnorstu',hex($_),1) } split //,'2fde0abe76c36c914586c';

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://234600]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (4)
As of 2024-04-24 20:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found