NAME

Regexp::Tr - Run-time-compiled tr/// objects.

SYNOPSIS

use Regexp::Tr;
my $trier = Regexp::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/// (eg: "e", etc.).

$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, so the user is responsible for backslashing the variable.

$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

AUTHOR

Robert Fischer, <chia@cpan.org>

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.

2 POD Errors

The following errors were encountered while parsing the POD:

Around line 123:

=over should be: '=over' or '=over positive_number'

Around line 130:

You forgot a '=back' before '=head1'