NAME
Regex::Tr - Run-time-compiled tr/// objects.
SYNOPSIS
use Regex::Tr;
my $trier = Regex::Tr->new("a-z","z-a");
my $swapped = "foobar";
$trier->bind(\$swapped); # $swapped is now "ullyzi"
my $tred = $trier->trans("barfoo"); # $tred is "yziull"
ABSTRACT
Solves the problem requiring compile-time knowledge of tr/// constructs by
generating the tr/// at run-time and storing it as an object.
DESCRIPTION
One very useful ability of Perl is to do relatively cheap transliteration via the
tr/// regex operator. Unfortunately, Perl requires tr/// to be known at compile-time.
The common solution has been to put an eval around any dynamic tr/// operations, but
that is very expensive to be used often (for instance, within a loop). This module
solves that problem by compiling the tr/// a single time and allowing the user to
use it repeatedly and delete it when it it no longer useful. The last instance to be created is stored for ease of recreation (for instance, within a loop).
METHODS
CLASS->new(FROMSTRING,TOSTRING,[MODIFIERS])
This creates a new instance of this object. FROMSTRING is the precursor string for
the tr///, TOSTRING is the succsessor string for the tr///, and the optional MODIFIERS
is a string containing any modifiers to the tr///.
$obj->bind(SCALARREF)
This binds the given SCALARREF and then performs the object's tr/// operation, returning
what the tr/// operation will return. Note that this method does not create the reference.
$obj->trans(SCALAR)
This takes a scalar, performs the tr/// operation, and returns the tr///ed string in
scalar context, or a list consisting of the tr///ed string and the tr/// return value
in list context.
SEE ALSO
* perlop - Provides a definition of the tr/// operator.
* perlre - Provides more information on the operator.
AUTHOR
Robert Fischer, <chia@corradiation.net>
COPYRIGHT AND LICENSE
Copyright 2003 by Robert Fischer
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.