Store a number as a string, while using up less space than if you were to write out the whole number. Example: The number 1819436368 (10 chars) can be stored as the string "Perl" (4 chars). Useful when you need to save
on space. See node
317125.
#!/usr/bin/perl -W
# Takes a number between 0 and 2^32,
# returns 4 characters (ASCII).
sub num_to_chars
{
my $packed = pack( "l", $_[0] );
return unpack( "A*", $packed );
}
# Takes 4 ASCII chars, returns a "long"
sub chars_to_num
{
my $chars = pack( "A*", $_[0] );
return unpack( "l", $chars );
}