Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re^2: Pimp My RegEx

by heathen (Acolyte)
on May 31, 2005 at 18:56 UTC ( #462170=note: print w/replies, xml ) Need Help??

in reply to Re: Pimp My RegEx
in thread Pimp My RegEx

I'll take your advice and pull out the "use english" command. I thought the "use english" syntax would be the kind thing to do for the benefit of my coworkers. They cringe when they see a complex regex and a "$/" will have them running to the camel book! Please elaborate on the "evil variables". I'm not really familiar with them and their implications.

Replies are listed 'Best First'.
Re^3: Pimp My RegEx
by jhourcle (Prior) on May 31, 2005 at 20:02 UTC

    Sometimes, a comment will work just as well, without the overhead. Consider the following:


    As another option, in the documenation for 'English', there's a suggestion to use:

    use English qw( -no_match_vars ) ;

    to prevent the problems mentioned.

    As for the 'evil variables', the following note is in 'perldoc perlre':

    WARNING: Once Perl sees that you need one of $&, $`, or $' anywhere in the program, it has to provide them for every pattern match. This may substantially slow your program. Perl uses the same mechanism to produce $1, $2, etc, so you also pay a price for each pattern that contains capturing parentheses. (To avoid this cost while retaining the grouping behaviour, use the extended regular expression "(?: ... )" instead.) But if you never use $&, $` or $', then patterns without capturing parentheses will not be penalized. So avoid $&, $', and $` if you can, but if you can't (and some algorithms really appreciate them), once you've used them once, use them at will, because you've already paid the price. As of 5.005, $& is not so costly as the other two.

      Thanks for the advice jhourcle!
      I've got a few scripts out there I'm going to have apply the "-no_match_vars" to. I didn't realize "Use English" came with baggage.

Re^3: Pimp My RegEx
by radiantmatrix (Parson) on May 31, 2005 at 20:01 UTC

    They cringe when they see a complex regex and a "$/" will have them running to the camel book!

    Add a comment?

    local $/ = $my_input_sep; # Custom input separator (instead of \n)

    Yoda would agree with Perl design: there is no try{}

Re^3: Pimp My RegEx
by eyepopslikeamosquito (Chancellor) on May 31, 2005 at 20:50 UTC

    Further to the other excellent responses, you can check if your script is infected with any of the evil variables with the Devel::SawAmpersand module.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://462170]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2018-05-26 12:17 GMT
Find Nodes?
    Voting Booth?