Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Why do we need $a and $b to be special?

by dakkar (Hermit)
on Jul 30, 2004 at 12:56 UTC ( #378662=note: print w/ replies, xml ) Need Help??


in reply to Why do we need $a and $b to be special?

In a module of mine (might event release it at some time), I needed the same functionality, so I wrote:

my $caller=(caller(1))[0]; no strict 'refs'; @out=sort { local (${"${caller}::a"},${"${caller}::b"})=($a,$b); $sort->($a,$b) } @in;

This might not give the fastest runtimes, but allows the user to pass a compare sub that works in any of the two ways.

-- 
        dakkar - Mobilis in mobile

Most of my code is tested...

Perl is strongly typed, it just has very few types (Dan)


Comment on Re: Why do we need $a and $b to be special?
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2015-07-28 04:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (252 votes), past polls