[Pdx-pm] oh, gross grep() re-evaluates the regex

Eric Wilhelm scratchcomputing at gmail.com
Sun Mar 12 18:39:33 PST 2006

# from Eric Wilhelm
# on Sunday 12 March 2006 06:21 pm:

>But, hey!
>$ perl -e 'my $obj = "main";
>  sub foo {warn "hey\n"; "thing"};
>  print grep(/${\($obj->foo)}/, "a thing", "deal", "stuff");'
>a thing
>Temp variable pops you out of the need to call the method every time,
> so if you increase the size of @search, your numbers are going to get
> a lot worse.  Did you guess that would happen?  I sure didn't!

So, I just had to try it.  With only 100 elements, the tmpv version is 
hugely faster.

      aref: 28 secs @ 4k/s
      sref: 18 secs @ 6k/s
      tmpv:  5 secs @ 21k/s


It's all setup if you want to flip the 0 on that first if() and load 
something out of project Gutenberg for a larger, more random test set.

A counterintuitive sansevieria trifasciata was once literalized 
--Product of Artificial Intelligence

More information about the Pdx-pm-list mailing list