Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

(jeffa) Re: (USING POE!) Re: 'better mousetrap': how to perform timed event

by jeffa (Bishop)
on Apr 23, 2003 at 23:59 UTC ( #252720=note: print w/replies, xml ) Need Help??


in reply to (USING POE!) Re: 'better mousetrap': how to perform timed event
in thread 'better mousetrap': how to perform timed event

Awesome ... i only have one nit-pick. ;)

Change the input match regex from:

$input =~ /$to_match/o
to:
$input =~ /\Q$to_match\E/
This will allow you to match metachars as regular characters. I also (rather cargo-cultish-ly) avoid using the o modifier. ask tye :D

eduardo++

maybe this should be added to POE Central?

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

Replies are listed 'Best First'.
Re: (jeffa) Re: (USING POE!) Re: 'better mousetrap': how to perform timed event
by eduardo (Curate) on Apr 24, 2003 at 03:39 UTC

    Ah yes... \Q and \E. I'll be honest, I'm not nearly crafty enough with regular expressions to have thought of that. As far as my perling goes, it has been rather surprisingly devoid of regular expressions. I've probably written 20-30k lines of perl code in my life, and alltogether, I've probably written 50 regular expressions in my code. Ah well, that's what we have maverick for :)

    I am however curious about the /o modifier on the re. I mean, if we know the "event" that the user is looking for, what is the reason for *not* using it? After all, as the code has been specified, it's a non-mutable trigger... is it simply an issue of pre-emptive maintenance coding headache prevention? I don't think I know tye nearly well enough to just badger him needlessly when I have you to thwack about :)

      Heh heh ... thwack away! ;)

      "... is it simply an issue of pre-emptive maintenance coding headache prevention?"

      I think so. What if you suddenly decide that the string you need to match needs to be dynamic? You forget to remove the o modifer and possibly spend a lot of time trying to find the bug when your regex stops matching. Here is some code to demonstrate:
      @data = qw(foo bar baz qux); { print "search: "; chomp ($in = <STDIN>); last unless $in; print $_,$/ for grep /\Q$in\E/o, @data; redo; }
      I figure why bother with such premature optimizations if they have the potential to bite.

      jeffa

      L-LL-L--L-LL-L--L-LL-L--
      -R--R-RR-R--R-RR-R--R-RR
      B--B--B--B--B--B--B--B--
      H---H---H---H---H---H---
      (the triplet paradiddle with high-hat)
      

        yet another perfectly usable, very useful facility of perl consigned to the bit-bucket of jaundiced opinion because one self-ascribed expert got bitten by it once.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2019-11-14 08:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Strict and warnings: which comes first?



    Results (76 votes). Check out past polls.

    Notices?