I've been banging my head against a brick wall on and off over this one
now.

I inherited some code that contain the following statement inside two
nested for loops:

eval "\$variable_hash->{'$variable'} =~ s/$search/$replace/$parameters;";

I did some benchmarking, and profiling to confirm my suspicions that
eval{} inside for(){for(){ ...}} is slooooow.

I thought there must be another way.

I found s/(?${parameter}:$search)/$replace/
This was working fine, until I found out that some instances of $replace
contain $1.

e.g.

  $search  = q[(.+)];
  $replace = q['$1'];

$search seems to arrive at the function containing this as a qr'd
regexp.

In this instance $parameters was empty.

In the code I'm fighting with $parameter is usually g or nothing.

If I passed the value "16/07/2002 14:58:09" to the eval() version I
would get: '16/07/2002 14:58:09'
If I pass the value "16/07/2002 14:58:09" to the s///, I get: '$1'

I'd really like to kill the eval() but don't know how to get
$replace expanded in the s/// version.

I've recently realised that you can't have s/(?g:$search)/$replace/ so
I've tweaked my code to check for g in $parameters and do s///g or s///
accordingly.

If anyone has any ideas/pointers/references/solutions I'd really like to
hear,


Chisel
-- 
e:   [EMAIL PROTECTED]   | A. Top posters.  Q. What is the most
w:   www.herlpacker.co.uk      | annoying thing in e'mail?  
gpg: D167E7FE                  | 

Reply via email to