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.
# Takes a number between 0 and 2^32,
# returns 4 characters (ASCII).
my $packed = pack( "l", $_ );
return unpack( "A*", $packed );
# Takes 4 ASCII chars, returns a "long"
my $chars = pack( "A*", $_ );
return unpack( "l", $chars );
I have used methods such as this with CGI. I needed to pass values in URLs such as session IDs and user IDs. Using methods such as this, a long session ID becomes a short char string. It also, in my opinion, helps disuade people form putting "random" stuff into your URLs in the hope that something interesting is seen (I know that this won't stop someone with the relevant skills, but it might stop the wannabes).
I agree with the previous comment that in native storage you gain nothing, but you can save space in other situations (such as URLs in e-mails where a long URL may wrap and become confusing).
Ugh. Numbers are stored in their native formats. I.e. 2^32 is stored in 4 bytes (2^8 * 4). Turning 4mil and change into characters gets you no-where. If you want to argue efficiency of storage, which is cheap, at least compress ala gzip :)
I was thinking of this as more of a storage benefit for homebrew ASCII databases, this will economize storage space on disk in applications where the database file is not compressed. After using the above code I noticed that CR and LF ASCII chars will appear in the files and thus mess up <FILE> operations...