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

Probably your mother language is English. It is low frequency language on comma occurrences. Then, your spell out module – this is a chomskian expression - process [a-bc-d] “more” productively than [a-b]|[c-d]. But, try to think out of your box, and you will can see that it is not necessary so. To me, what you gain in reducing length, suppressing OR operators, you loose in readability. Any way, thanks for the free wisdom.

Replies are listed 'Best First'.
Re^3: Is Text::RE::Foo a good name space?
by ikegami (Patriarch) on Oct 11, 2007 at 18:42 UTC

    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.

      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/; }