Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^2: Is Text::RE::Foo a good name space?

by fernandes (Monk)
on Oct 11, 2007 at 18:04 UTC ( [id://644297]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://644297]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-04-25 05:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found