in reply to Precompiling qr/.../o question

I haven't looked at the source-code myself, but I would expect for regular-expressions to be bound to a certain scope and for them to be cached ... say, by the expanded regular-expression string. Given a particular pattern to evaluate, you would first peek to see if it's in the cache and if so re-use it. It is my understanding that this is precisely what recent Perl implementations do.

Replies are listed 'Best First'.
Re^2: Precompiling qr/.../o question
by ikegami (Patriarch) on Apr 08, 2008 at 04:28 UTC

    It is my understanding that this is precisely what recent Perl implementations do.

    Then your understanding is flawed. There's a cache, but it only holds one value: the last regexp compiled for that operator instance.

    >perl -Mre=debug -e"qr/$_/ for qw( foo bar bar foo )" 2>&1 | find "Com +piling" Compiling REx `foo' Compiling REx `bar' Compiling REx `foo'