Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^2: Check if sort has changed order (eq)

by Anonymous Monk
on May 10, 2013 at 09:47 UTC ( [id://1032927]=note: print w/replies, xml ) Need Help??


in reply to Re: Check if sort has changed order (eq)
in thread Check if sort has changed order

Ha, stupid memory allocation tricks

my @f = ( 4, 2 ); print join ' ', int \$_, \$_, "$_\n" for @f;print "\n"; @f = sort @f; print join ' ', '#', int \$_, \$_, "$_\n" for @f;print "\n"; my $prev = 0; for my $next ( @f ){ if( $prev ){ die "BEEN SORTED" if $prev > \$next; } $prev = \$next; } __END__ $ perl fa 4165804 SCALAR(0x3f90ac) 4 4165980 SCALAR(0x3f915c) 2 # 4165980 SCALAR(0x3f915c) 2 # 4165804 SCALAR(0x3f90ac) 4 BEEN SORTED at fa line 8.

Replies are listed 'Best First'.
Re^3: Check if sort has changed order (eq)
by Krambambuli (Curate) on May 10, 2013 at 10:43 UTC
    That won't work for whatever sort condition.

    I'd probably rather compare the MD5 checksum of the scalar references in the list before and after the sort.

      That won't work for whatever sort condition.

      Sure it will, its comparing memory addresses not data, so the sort condition is irrelevant; only relevant are how much ram you have and how you initialized the array; if the memory addresses aren't sequential before sorting, it won't work.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2024-04-26 04:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found