in reply to Regex combining /(foo|bar)/ slower than using foreach (/foo/,/bar/) ???  

I think that your proposed optimization isn't as straightforward as you think. Consider:

$string = "fooar" $string =~ s/(foo|bar)/b/g; print $string;

vs.

$string = "fooar" $string =~ s/$_/b/g for (qr/foo/, qr/bar/); $print $string;

Replies are listed 'Best First'.
Re^2: Regex combining /(foo|bar)/ slower than using foreach (/foo/,/bar/) ???
by Anonymous Monk on Feb 19, 2005 at 07:52 UTC
    exactly. Problem for me is, that if I've got a soulution in the language I use it as it is hopefuly perfectly optimized.

    It feels like on those old VAX systems where you could program in assembler some operations faster with simpler ops. One of the reasons RISC was introduced.

    If Perl gives me the possiblity of using a 'nice' small solution (/foo|bar/) I always thought I should be able to program a faster solution with a perl PROGRAM ( the for loop ).

    But that's just propably my understanding of how things should work.

    Jolly - thanx for u'r time.

      If Perl gives me the possiblity of using a 'nice' small solution (/foo|bar/) I always thought I should be able to program a faster solution with a perl PROGRAM ( the for loop ).

      I wouldn't think that. At least, not if you're smart about language design. With good semantics, you provide the optimizer more information about what you're trying to do, thus allowing it to make better optimization. Unfortuately, Perl5 has hopelessly bad semantics, so this principle is mostly lost for us.

      "There is no shame in being self-taught, only in not trying to learn in the first place." -- Atrus, Myst: The Book of D'ni.