> From: "Ph. Marek" <[EMAIL PROTECTED]>
> Date: Wed, 12 Feb 2003 08:42:57 +0100
> 
> --Boundary-00=_BsfS+fOE40iabfr
> Content-Type: text/plain;
>   charset="us-ascii"
> Content-Transfer-Encoding: 7bit
> Content-Disposition: inline
> 
> Hello everybody,
> 
> I've sometimes the task to analyse a string 
> starting from a given position, where this position 
> changes after each iteration. (like index() does)
> 
> 
> As this is perl there are MTOWTDIIP but I'd like 
> to know the fastest.
> 
> So I used Benchmark.pm to find that out. (script attached)
> 
> 
> Excerpt from script:
>   "from_start"  => sub { m/\S*\s+(\S+)/; },
>   "re_dyn"  => sub { m/^[\x00-\xff]{$pos}\S*\s+(\S+)/; },
>   "re_once" => sub { m/^[\x00-\xff]{$pos}\S*\s+(\S+)/o; },
>   "substr" => sub { substr($_,$pos) =~ m/\S*\s+(\S+)/; },
>   "substr_set" => sub { $tmp=substr($_,$pos); $tmp =~ m/\S*\s+(\S+)/; },
> 
> from_start is for comparision only as it should be.
> re_once is for comparision too as the index can't be adjusted.
> (and dynamically recompiling via eval() for changing indexes can't
> be fast enough)

Phil, please see the perlfunc entry for "pos" and the perlre section
on \G.  This is what you need.

Luke

Reply via email to