On Tue, Feb 11, 2003 at 06:27:15PM -0500, Uri Guttman wrote: > >>>>> "BR" == Bob Rogers <[EMAIL PROTECTED]> writes: > > > BR> I would like to point out that your code can be improved by replacing > BR> uses of $& and $` with parentheses in the regexes followed by $1 and > BR> $2. This is from the Devel::SawAmpersand doc . . . > > BR> I was unaware of this issue; thanks for bringing it to my attention. > BR> But Devel::SawAmpersand doesn't really explain the problem in any kind > BR> of depth, and just talks about "massive in-memory copying." So, > BR> presumably, this is just a question of efficiency? > > the problem only happens with s///. if you use $&, then all uses of s/// > must do a full copy of the original string in case parts of it are > referred to by $& (and friends). the s/// could change the string and so > a copy must be made. this is true for all instances of s/// in your > program. if you use parens then only those instances will need extra > copies.
Just to clarify, there is a problem with any code that does anything to any of the three variables, if that code is intended for use in programs that may use regexes heavily. Since a module or "library" should not assume things about what kind of programs will use it, essentially all code should avoid them. In one-liners without performance concerns, they are not a problem. More details are in `perldoc perlvar` and the perl5-porters mailing list archives. -- John Tobey <[EMAIL PROTECTED]> \____^-^ /\ /\ _______________________________________________ Boston-pm mailing list [EMAIL PROTECTED] http://mail.pm.org/mailman/listinfo/boston-pm