Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re^6: Sort undef

by marinersk (Priest)
on Aug 15, 2017 at 10:48 UTC ( #1197412=note: print w/replies, xml ) Need Help??

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

Going back to my attitude when I was a C programmer: It pays to know how your compiler thinks. (Needs adjustment for application to modern use of Perl, but the sentiment is the same.)

Adding/replacing these three lines into my original script above:

use Encode qw( encode_utf8 ); my $x = chr(1 << 63); my @Unsorted = ( 'Dog', 'Cat', 'Bird', undef, $x, 'Elephant', undef, ' +Lizard' );


S:\Steve\Dev\PerlMonks\P-2017-06-12@0734-sort-undef>perl .\ ---------------------------------------------------------------------- +--------- Original: ---------------------------------------------------------------------- +--------- Dog Cat Bird (undef) Wide character in print at .\ line 58. Elephant (undef) Lizard ---------------------------------------------------------------------- +--------- ---------------------------------------------------------------------- +--------- Custom Sort: ---------------------------------------------------------------------- +--------- Bird Cat Dog Elephant Lizard (undef) (undef) Wide character in print at .\ line 58. ---------------------------------------------------------------------- +--------- S:\Steve\Dev\PerlMonks\P-2017-06-12@0734-sort-undef>

A string of chr(255)bytes longer than the longest item in the original array still fails to sort to the bottom; knowing that Unicode characters are stored differently than old-fashioned ASCII strings empowers the Perl programmer to make a better choice.

Thank you for the information!

I'd upvote the post, but there isn't any point, as it's Anonymous Monk.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2022-05-21 05:25 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (76 votes). Check out past polls.