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

Re: A "strange" behaviour, at least to me :)

by NetWallah (Abbot)
on Apr 13, 2013 at 17:28 UTC ( #1028538=note: print w/ replies, xml ) Need Help??


in reply to A "strange" behaviour, at least to me :)

Perl is mis-parsing the line :

# 2 @values = sort arraynosort(Values=>\@orig_values);
as
@values = (sort arraynosort 'Values', \@orig_values);
and using the "arraynosort" as a Sort sub.

Adding parens fixes it:

@values = sort (arraynosort(Values=>\@orig_values));
An alternative fix is to give "sort" an empty "block", because it wants one:
@values = sort {},arraynosort(Values=>\@orig_values);

             "I'm fairly sure if they took porn off the Internet, there'd only be one website left, and it'd be called 'Bring Back the Porn!'"
        -- Dr. Cox, Scrubs


Comment on Re: A "strange" behaviour, at least to me :)
Select or Download Code
Re^2: A "strange" behaviour, at least to me :)
by ikegami (Pope) on Apr 13, 2013 at 17:36 UTC
    @values = sort {},arraynosort(Values=>\@orig_values);
    passes a hash ref to sort. You meant
    @values = sort { $a cmp $b } arraynosort(Values=>\@orig_values);

    By the way, the least invasive solution is:

    @values = sort +arraynosort(Values=>\@orig_values);

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (8)
As of 2014-12-21 03:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (102 votes), past polls