> if ($buffer =~ /MARKER/)
> {
>       $buffer = $&
>       #OR something like:
>       #$buffer = substr($buffer,0,$-[0]);
>       #OR even:
>       #$markerpos = index($buffer,MARKER);
>       #$buffer = substr($buffer,0,$markerpos);
> }
>   
Not that I'm an RE guru or anything but my code could look like 
something like this:

# consider the marker to be '#'
$buffer = $1 if ($buffer =~ /(.*)#/);

Simple, sweet and to the point. I'm sure there are faster ways to do 
this, but considering I run about a million iterations of this in 1.5 to 
2 secs, it's fast enough. For me. In my small test. YMMV - you don't 
mention the size of buffer, the size of marker, how often/time-critical 
it can be. Also, nothing about the characteristics of the buffer, for 
example, if the marker may occur several times - if so for example, you 
might wish to make the * nongreedy:

# consider the marker to be '#'
$buffer = $1 if ($buffer =~ /(.*?)#/);

Then again, maybe the index/substr technique is better - it seems a lot 
faster:

# consider the marker to be '#'
my $pos = index($buffer, '#');
$buffer = substr($buffer, 0, $pos) if $pos >= 0;

There are many ways to achieve your goal, but I guess only you can tell 
as you know most about the characteristics of the data...FWIW, I 
could'nt get $` to work. Sure, there are discussions about 
maintainability that could be held, but there are as many opinions as 
people so...

In general, I think Bill is right - don't worry too much about it. If 
you need to optimize, do it later - if it's ever needed.

ken1


_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to