NAME

Sort::Packed - Sort records packed in a vector

SYNOPSIS

use Sort::Packed qw(sort_packed);
my $vector = pack 'l*' => 12, 435, 34, 56, 43, 7;
sort_packed l => $vector;
print join(', ', unpack('l*' => $vector)), "\n";

DESCRIPTION

This module allows to sort data packed in a perl scalar.

Internally it uses a radix sort algorithm that is very fast.

EXPORT

The following functions can be imported from this module:

sort_packed $template => $data

sorts the records packed inside scalar $data.

$template is a simplified pack template. It has to contain a type indicator optionally followed by an exclamation mark and/or a repetition count. For instance:

"n" => unsigned short in big-endian order
"l!" => native signed long
"L!4" => records of four native unsigned longs
"C256" => records of 256 unsigned characters

The template can be prefixed by a minus sign to indicate descending order (for instance, -n4).

Sub-byte size or variable length types can not be used (for instance, bit b, hexadecimal h, unicode U or BER w types are forbidden).

Currently, templates containing several types (as for instance "nL") are not supported.

reverse_packed $template => $data

reverses the order of the records packed inside scalar $data.

SEE ALSO

Perl builtins "pack" in perlfunc and "sort" in perlfunc.

My other sorting modules Sort::Key and Sort::Key::Radix.

The Wikipedia article abour radix sort: http://en.wikipedia.org/wiki/Radix_sort.

BUGS AND SUPPORT

None known, but this is an early release!

Send bug reports via the CPAN bug tracking system at http://rt.cpan.org or just drop my an e-mail with any problem you encounter while using this module.

COPYRIGHT AND LICENSE

Copyright (C) 2008 by Salvador Fandiño (sfandino@yahoo.com).

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.10.0 or, at your option, any later version of Perl 5 you may have available.