in reply to Re: Re: Grep Pattern Match
in thread Grep Pattern Match

This is just a slight optimization - read up on qr// in perlop to get the full scoop.

$match = qr/^nc$digyear$digmon.*\.log$/; @files = grep m/$match/, @files;

Fun Fun Fun in the Fluffy Chair

Replies are listed 'Best First'.
Re: Re^3: Grep Pattern Match
by BrowserUk (Patriarch) on Dec 27, 2002 at 16:17 UTC

    Slightly dangerous if the application calls for using the regex in a loop where one of the variables (eg. $month) changes, as unless the qr// is also inside the loop (in which case the optimisation benefits are lost), as the changing value of the variable won't be recognised.


    Examine what is said, not who speaks.

      I am not really going for optimisation (yet)... just want a script that will parse my log files that will search for attempted DOS's and stuff and then take those IP's and add them to our deny list. That is all I am writing this for.

      -----------------------
      Billy S.
      Slinar Hardtail - Hand of Dane
      Datal Ephialtes - Guildless
      RallosZek.Net Admin/WebMaster

      perl -e '$cat = "cat"; if ($cat =~ /\143\x61\x74/) { print "Its a cat! +\n"; } else { print "Thats a dog\n"; } print "\n";'

        Um, no. Not sure, sure, but that is what I believe to be the case following various discussions regarding the use of qr// and the contrast between it, using /o on a specific m// or s///, and the utility (or otherwise) of using the /o operator in conjuction with qr//o.

        What I think (though) that the concensus was that using /o on the qr// operator was a waste of time as qr// effectively already did once-only compilation.

        It's quite possible I have misinterreted this (again), and given that it's you that challenging my assumptions, and your likely to reply with a Devel::* dump demostrating that this is not the case, I'll turn the statement into a question and ask....Is this slightly dangerous?


        Examine what is said, not who speaks.