Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^3: Sort undef

by choroba (Archbishop)
on Jun 12, 2017 at 13:55 UTC ( #1192590=note: print w/replies, xml ) Need Help??


in reply to Re^2: Sort undef
in thread Sort undef

> actually it works undef is not cast to "" and hence less than empty string

No, it works because sort is stable and you declared the lucky case to be the input. Try again with

use List::Util qw{ shuffle }; my @array = shuffle((undef) x 3, qw/c b a/, ("") x 3);

($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

Replies are listed 'Best First'.
Re^4: Sort undef
by LanX (Sage) on Jun 12, 2017 at 14:18 UTC
    Ah, thanks! :)

    > you declared the lucky case to be the input

    In my defence:

    To be sure I also tried

     my @array =  ( ("")x3, (undef)x 3, qw/c b a/, ("")x3, (undef) x3 );

    which still gives for cmp_undef1

    [ "", "", "", "", "", "", "a", "b", "c", undef, undef, undef, undef, undef, undef, ]

    which seems to be another "lucky case".

    I don't know how "stable" is defined but it turns out to be not that easy to construct a counterexample without shuffle.

    my @array =  ( undef, "", qw/c b a/, "", undef  );

    ->

    ["", "a", "b", "c", undef, "", undef]

    Cheers Rolf
    (addicted to the Perl Programming Language and ☆☆☆☆ :)
    Je suis Charlie!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2022-01-21 00:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (57 votes). Check out past polls.

    Notices?