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

A rather simpler test method, but in this, (only) "line 1" is printed out 10 times.

#! perl -sw use strict; my $count=1; my $regex = qr/$count/; my $told = tell DATA; my $line; for $count (1 .. 10) { $line =~ $regex and print $line while $line = <DATA>; seek DATA, $told, 0; } __DATA__ line 1 line 2 line 3 line 4 line 5 line 6 line 7 line 8 line 9

Examine what is said, not who speaks.

Replies are listed 'Best First'.
Re^9: Grep Pattern Match
by diotalevi (Canon) on Dec 27, 2002 at 19:48 UTC

    Oh but that's not at all the same. It's quite obvious (to me anyway) that $count is being compiled each time. The only reason I brought this up was I didn't know whether the invariant regex in a block attacked to a grep was going to be recompiled each time or not. There's an opportunity for perl to notice that the regex only needs to compiled once - the question here is on whether it takes it or not.

    Update: Oops! I thought you said $line =~ $count where you actually said $line =~ $regex. Anyhow I still think you've misunderstood which question I was asking.


    Fun Fun Fun in the Fluffy Chair