I want to use the pack() function in Perl to encode some data. Then I want to compare my packed structure to another packed structure. I want this compare to be on the byte values of this packed structure.
According to the documentation, cmp uses the current locale to determine how to compare strings. But I don't want any intelligence applied to the comparison. I want whatever is closest to a memcmp(). Obviously I cannot use <=>
for comparing my packed objects as they are not numbers.
What is the best way to compare packed strings in Perl?
Sidenote: I have been reading this article on efficient sorting in Perl which notes that the plain sort function uses a memcmp-like algorithm for comparing structures. I'm wondering how to achieve such a comparison without having to use sort.
sort
is really an excellent place to start from. Trying to build your own sort-replacement will probably not work as well as you'd like, as the Perl sort has been finely tuned over years. The efficient sorting link you gave actually includes instructions on how to use packed data structures to speed the sort, which is pretty clever, but the sorting would have to be taking a long time before I'd devote myself to maintaining that. – Belding