in reply to Re^2: Is Text::RE::Foo a good name space?
in thread Is Text::RE::Foo a good name space?

I must admit I realized it was less readable as I was posting. I wonder if there's a significant speed difference, since this regexp is likely to be used repeatedly. Either way, the regex could be built dynamically when the module is loaded. That would allow for much more readable code than any of the alternatives we've seen in this thread.

  • Comment on Re^3: Is Text::RE::Foo a good name space?

Replies are listed 'Best First'.
Re^4: Is Text::RE::Foo a good name space?
by blah (Novice) on Oct 12, 2007 at 16:57 UTC
    alternations are slower, but tr is faster for simple expressions:
                   Rate alternate    single        tr
    alternate  631309/s        --      -80%      -86%
    single    3198780/s      407%        --      -27%
    tr        4411077/s      599%       38%        --
    
    use Benchmark qw(cmpthese); cmpthese(-1, { alternate => \&alternate, single => \&single, tr => \&tr_op }); my $s; BEGIN{ $s = 'this is a string'; } sub alternate { return $s =~ /[a-b]|[c-d]|[e-f]/ ; } sub single { return $s =~ /[a-f]/; } sub tr_op { return $s =~ tr/a-f/a-f/; }