clinton has asked for the wisdom of the Perl Monks concerning the following question:
What I would like to do is to load a language-specific regex on demand.
Is this a decent way of doing it?
package XYZ; my %Regexes; sub regex { my $class = shift; my $lang = shift || 'en'; unless (exists $Regexes{$lang}) { my $regex_class = "${class}::$lang"; eval qq{require $regex_class}; if ($@) { die "Error loading regex for lang '$lang' : $@"; } $Regexes{$lang} = $regex_class->regex() } return $Regexes{$lang} } package main; my $regex = XYZ->regex('en')
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Loading a language specific regex on demand
by Fletch (Bishop) on Apr 04, 2007 at 13:44 UTC |