in reply to Re: large hash of regex substitution strings
in thread large hash of regex substitution strings

Thanks. What about the following example ?
s/^\s+\(Text [aA].* (\d+:\d+ .*$)/\.T1 "$1/g;
I ask as I have about 50 regexs to work with.
I could build this out like this:
%search ( 1 => "s/^\s+\(Text [aA].* (\d+:\d+ .*$)/", 2 => ..... ); $replace ( 1 => "/\.T1 \"$1/", 2 => ..... ); Now I'd like to do something like this, and I know qr// fits in to the equation, I just dont know how .... yet :) while <VRUN> { s/$search/$replace/g; }
Thanks for taking a further look at this. Thanks again.

Replies are listed 'Best First'.
Re^3: large hash of regex substitution strings
by ikegami (Patriarch) on Oct 19, 2007 at 20:42 UTC

    Is there a pattern between the different operations? If not, you might be stuck with

    my @ops = ( sub { s/^\s+\(Text [aA].* (\d+:\d+ .*$)/\.T1 "$1/g; }, ... ); while (<$fh>) { foreach my $op (@ops) { $op->(); } }

    The reason it can't be simplified much is the $1 in the replace expression. Often, when reaching this point, it's time to look into a templating system. It's hard to tell if that's the case here since I'm only getting a very small picture of what you are doing.

Re^3: large hash of regex substitution strings
by Anonymous Monk on Oct 07, 2007 at 23:58 UTC
    Further to the above:
    %search ( R1 => "/^\s+\(Text [aA].* (\d+:\d+ .*$)/", R2 => ..... ); $replace ( R1 => "/\.T1 \"$1/", R2 => ..... ); while <VRUN> { foreach $rule ( keys %search ) { s/$search{$rule}/$replace{$rule}/g; } }
    My only concern is the substring match in R1/S1. Can I use qr// to make this more efficient, and if so, what is the correct syntax. Would qr// be required on both sides of the s// ? Do i need to use an eval or an /ee modifier to get the substitution to happen ? Thanks again all you p'gurus for your help on this :)