in reply to [perlre] using qr - help needed

Why aren't you guys using the /o modifier?

Replies are listed 'Best First'.
Re: Re: [perlre] using qr - help needed
by broquaint (Abbot) on Nov 08, 2002 at 15:19 UTC
    Because qr compiles the regex it makes the /o modifier rather superfluous. It does however apply to situations where you have a match which has a variable in it and you only want it to be compiled once e.g
    my $match = shift @ARGV; my @matched = grep /^$match$/o, <>;
    So there the regex will only be compiled once instead for each iteration within the grep. See the perlop|perlop manpage for more info.
    HTH

    _________
    broquaint

      That can be done with qr// as well though.
      my $rx = qr/^@{[shift @ARGV]}$/; my @match = grep /$rx/, <>;
      qr// also is much less likely to be used mistakenly than /o and much easier to spot when it is. /o should be considered a relic from pre-qr// times that has few if any uses anymore.

      Makeshifts last the longest.