NAME
Convert::ASCII::String - convert character strings to ASCII and vice versa.
SYNOPSIS
use Convert::ASCII::String q/:all/;
our $wisdom = 'Premature optimization is the root of all evil.';
string2ascii (\$wisdom, '.');
80.114.101.109.97.116.117.114.101.32.
111.112.116.105.109.105.122.97.116.105.
111.110.32.105.115.32.116.104.101.32.114.
111.111.116.32.111.102.32.97.108.108.32.
101.118.105.108.46
ascii2string (\$wisdom, '.');
Premature optimization is the root of all evil.
DESCRIPTION
Convert::ASCII::String
basically converts strings to ASCII and vice versa. It uses perl's built-in functions pack & unpack. Most time these functions prove to be sufficient if data has to be converted and remains within memory.
Pack & unpack rely upon arrays to convert data and not without reason though. Preserving multiple ASCII codes in a single string conveys some difficulty since its hard to distinguish where from and where to each ASCII code ranges.
Convert::ASCII::String
solves this problem by allowing inserting a item separator between each ASCII code (preferably a non-numeric value).
Appropriate usage
In most cases the usage of this module will prove to be inappropriate. If data will remain within memory, then array ASCII conversion using pack & unpack is appropriate and presumably faster than using Convert::ASCII::String
.
Convert::ASCII::String
uses join & split among pack & unpack to merge array to strings and vice versa. Thus wise usage is recommended since such operations may slow down converting if much data has be transformed. So, when to use then?
Whenever data has to be converted to ASCII and has to be stored on a disk or other mediums where it will freed from the array it was previously kept in. pack & unpack will not be able to convert an array to character if not each single ASCII code takes up its own index within the array. Thus string transformation with an item separator.
FUNCTIONS
string2ascii
Converts a character string to ASCII inserting a separator between each ASCII code.
The separator is optional.
string2ascii (\$data, '.');
or
string2ascii (\$data);
Beware, second option will not allow back converting from ASCII.
RETURN CODES
ascii2string
And vice versa.
ascii2string (\$data, '.');
RETURN CODES
OPTIONS
The separator may alternatively be set by
$Convert::ASCII::String::sep = '.';
Function delivery becomes then superfluous.
EXPORT
string2ascii(), ascii2string()
upon request.
TAGS
:all - *()
SEE ALSO
perl(1)
LICENSE
This program is free software; you may redistribute it and/or modify it under the same terms as Perl itself.
AUTHOR
Steven Schubiger