in reply to Re: Performance Question
in thread Performance Question

Yes, that's what I want, and definitely not any warning messages saying things like "Use of uninitialized value..."

Replies are listed 'Best First'.
Re^3: Performance Question
by Rhandom (Curate) on Feb 28, 2007 at 17:22 UTC
    If you want to only swap in values that exist then use the following:
    s{(<\?--(\w+)-->)}{ defined($swap{$2}) ? $swap{$2} : $1 }eg;

    That will only replace values that match have a corresponding entry in %swap.

    If you are brave you can use something like this:
    s/<\?--(\w+)-->(??{ defined($swap{$^N}) ? '(?=)' : '(?!)' })/$swap{$1} +/g;

    It also does what you are looking for - but without the e modifier on the swap. You will probably need to read perlre to follow it fully - but essentially you are using the (??{}) block to check your regex as you go and then using ?= and ?! to report success or failure.

    my @a=qw(random brilliant braindead); print $a[rand(@a)];