>Bill Luebkert said:
>It would help if you gave an example of what you're trying to accomplish.
>I've used those vars maybe once or twice in testing, but never found a
>need for them in any of my normal scripts (but then again, I bleieve number
>vars ($1, $2, ...) have the same cost which I do use frequently).
>
>It's a one-time penalty and I wouldn't really worry much about it.  You
>could time it and see what the penalty actually is and see if it's
>warranted.

Bill,

According to sawampersand.pm :

There's a global variable in the perl source, called PL_sawampersand.
It gets set to true in that moment in which the parser sees one of $`,
$', and $&. It never can be set to false again. Trying to set it to
false breaks the handling of the $`, $&, and $' completely.

If the global variable C<PL_sawampersand> is set to true, all
subsequent RE operations will be accompanied by massive in-memory
copying, because there is nobody in the perl source who could predict,
B<when> the (necessary) copy for the ampersand family will be needed.
So B<all> subsequent REs are considerable slower than necessary.

End quote

So the "bad variables" I'm concerned about are not the same as the $1, $2
variables, nor is it a "one time hit" as you indicate.

What I'm doing is detecting if a marker exists in a string then truncating
it at the marker point ie:

if ($buffer =~ /MARKER/)
{
        $buffer = $&
        #OR something like:
        #$buffer = substr($buffer,0,$-[0]);
        #OR even:
        #$markerpos = index($buffer,MARKER);
        #$buffer = substr($buffer,0,$markerpos);
}

It's just an efficiency question that I suppose is not critical in my
program but I always like to write efficient, maintainable code. Also I'm
still in the implementation phase, and can't really do timed tests until
later, so I was hoping a Guru (like yourself, or someone from activestate)
would have some personal knowledge on the matter.

-Wayne Simmons

--
Software Engineer
InterSystems USA, Inc.
303-858-1000 
 

-----Original Message-----
From: Bill Luebkert [mailto:[EMAIL PROTECTED] 
Sent: Monday, January 28, 2008 5:32 PM
To: Wayne Simmons
Cc: [email protected]
Subject: Re: $& and friends

Wayne Simmons wrote:
> Ok I've read in the docs that $& and his mates $' and $` and some bad boys
> that slow down all regular expressions in an entire program. So in an
effort
> to prevent having to use them I was going to use either:
> @- and @+
> Or 
> The index function
> 
> I was wondering if anyone knows whether the @- and @+ system variables
were
> bad like the saw ampersand and friends.  
> 
> Also would they be better to use than searching the string again using the
> index function?





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

Reply via email to