in reply to New regex trick...

So, to simply remove '.z' you go in all the trouble of doing the '.*' (glob all) match etc etc. Whereas a shorter version must be faster:
$str =~ s/\..$//;
Unless I'm missing some other deeply nested point {griN}

_____________________
# Under Construction

Replies are listed 'Best First'.
Re: Re: New regex trick...
by japhy (Canon) on Jul 22, 2002 at 19:33 UTC
    Yours is a very special case, because we know there's only one character after the last ".". Here is a benchmark I ran with my new patch:
    use Benchmark 'cmpthese'; my $str = join '.', 'a' .. 'z'; cmpthese(-5, { old => sub { (my $x = $str) =~ s/(.*)\..*/$1/ }, new => sub { (my $x = $str) =~ s/.*\K\..*// }, }); __END__ new: 109650.19/s (n=578953) old: 45258.35/s (n=241227)
    ... which is an incredible speed increase!

    _____________________________________________________
    Jeff[japhy]Pinyan: Perl, regex, and perl hacker, who'd like a job (NYC-area)
    s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;