in reply to Re: Fast way to check if a sort was done (using stringification is *broken*)
in thread Fast way to check if a sort was doen

my $signature = md5(pack('(J/a*)*', @array));

should do the trick quickly.

Update: Of course, md5 really doesn't add anything. You could just use

my $signature = pack('(J/a*)*', @array);

Replies are listed 'Best First'.
Re^3: Fast way to check if a sort was done (using stringification is *broken*)
by bobf (Monsignor) on Jun 29, 2007 at 04:13 UTC

    Nice solution! I didn't know about '/' in pack.

    It's not quite perfect, though. It treats the empty string and undef as equal (there may be more ways to break it - this is just the first one I thought of):

    my $signature_1 = pack( '(J/a*)*', '', undef ); my $signature_2 = pack( '(J/a*)*', undef, '' ); printf( "Signatures are %s\n", ( $signature_1 eq $signature_2 ) ? 'equal' : 'unequal' ); # eq +ual!

    These cases were not specified in the OP. I apologize for being pedantic. :-)