in reply to regex problem!

Boy oh boy...

$name = (split/-\d/,$string)[0];

Just never use it on anything that starts with -\d.

antirice    
The first rule of Perl club is - use Perl
The
ith rule of Perl club is - follow rule i - 1 for i > 1

Replies are listed 'Best First'.
Re: Re: regex problem!
by Skeeve (Parson) on Jul 18, 2003 at 10:52 UTC
    Question:
    Could it be that
    ($name) = split /-\d/,$string,2;
    is more efficient regarding time and/or memory than your solution?

    Just wonder because I thought that this will just split into two array elements, thus saving some memory (maybe) but at least some time.

      Yes, it is.

      Benchmark: running mine, yours for at least 3 CPU seconds... mine: 3 wallclock secs ( 3.03 usr + 0.00 sys = 3.03 CPU) @ 27 +8704.16/s (n=844822) yours: 3 wallclock secs ( 3.13 usr + 0.00 sys = 3.13 CPU) @ 34 +5612.45/s (n=1082739) Rate mine yours mine 278704/s -- -19% yours 345612/s 24% --

      antirice    
      The first rule of Perl club is - use Perl
      The
      ith rule of Perl club is - follow rule i - 1 for i > 1