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

Re: Sorting problem with Orcish Manuever

by japhy (Canon)
on May 22, 2006 at 12:26 UTC ( [id://550917]=note: print w/replies, xml ) Need Help??


in reply to Sorting problem with Orcish Manuever

It's your return() statement. You've got return (X) or (Y) which Perl reads as (return(X)) or (Y), and since return() ALWAYS returns, you never get to the second clause. Rewrite it as return ((X) or (Y)) or, in your specific case, return X or Y.

And if you find any typos or errors otherwise in the article, please let me know. A problem I noticed looking at it right now is that the orcish maneuver should really be:

my $data_a = exists($cache{$a}) ? $cache{$a} : ($cache{$a} = mangle($a +)); my $data_b = exists($cache{$b}) ? $cache{$b} : ($cache{$b} = mangle($b +));
to allow for false and undefined values to be returned by mangle().

Jeff japhy Pinyan, P.L., P.M., P.O.D, X.S.: Perl, regex, and perl hacker
How can we ever be the sold short or the cheated, we who for every service have long ago been overpaid? ~~ Meister Eckhart

Replies are listed 'Best First'.
Re^2: Sorting problem with Orcish Manuever
by bart (Canon) on May 22, 2006 at 12:39 UTC
    That's no longer "Orcish", is it? "Orcish" (for "or-cache, implies use of "||=". The fact that some stuff may return false and thus be recalculated, is something you have to weigh against the ease of coding.

    Usually, it's rather rare. In this case, you will never get a false value back. So it's completely unnecessary.

Re^2: Sorting problem with Orcish Manuever
by roboticus (Chancellor) on May 22, 2006 at 16:40 UTC
    japhy:

    Thanks! I stared at that routine until I was blue in the face. I originally left the parentheses out, but had an entirely different bug in an earlier version. Then I left in the parentheses in 'cause I thought it looked good and wouldn't affect the value.
    <headsmack force="5">D'oh!</headsmack>

    --roboticus

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2024-04-18 09:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found