in reply to Re: Multiline Regex replacement in Multiline file
in thread Multiline Regex replacement in Multiline file

Hello Grimy,

This is a nice idea, but unfortunately, as long as the regex contains metacharacters, it can’t be made to work, because $1 will never contain those metacharacters:

#! perl use strict; use warnings; use Data::Dump; my $re = 'aaa\s+bbb'; my %dic = ($re => 'new'); my $s = 'aaa bbb'; $s =~ s/($re)/$dic{$1}/; print "\$1 = $1\n"; print "\$s = $s\n"; print "\%dic = "; dd \%dic;

Output:

19:34 >perl 1011_SoPW.pl Use of uninitialized value within %dic in substitution iterator at 101 +1_SoPW.pl line 10. $1 = aaa bbb $s = %dic = { "aaa\\s+bbb" => "new" } 19:34 >

Sorry, :-(

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Replies are listed 'Best First'.
Re^3: Multiline Regex replacement in Multiline file
by akamboj84 (Novice) on Sep 16, 2014 at 01:19 UTC
    Hello Athanasius, Is there any workaround for this ? as my regex file is a long one and also i need to process a lot of files, so its kind of time/cpu consuming. I want to get rid of "for" loop as mentioned in reply to your previous post