in reply to Regex stored in a scalar
ran it with script.pl \),\( \)\n\(use strict; use warnings; print "Enter left side for search: "; my $LeftSide = <STDIN>; print "Enter right side replacement: "; my $RightSide = <STDIN>; chomp($LeftSide); chomp($RightSide); while(<DATA>){ print if s/$LeftSide/$RightSide/g; #print "Replaced \"$LeftSide\" with \"$RightSide\" at: line $.: $_ +" if ($_ =~ s/$LeftSide/$RightSide/g); } __DATA__ hello this. is line 2 line, 3 ),( this is test for line 4 ) testing line ,5 now testing line (6)
C:\Users\James\Desktop>test.pl \),\( \)\n\( Replaced "\),\(" with "\)\n\(" at: line 3 "line, 3 \)\n\("
Posting some example input would be helpful :)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Regex stored in a scalar
by Laurent_R (Canon) on Aug 21, 2015 at 20:11 UTC | |
by james28909 (Deacon) on Aug 21, 2015 at 20:15 UTC | |
|
Re^2: Regex stored in a scalar
by poj (Abbot) on Aug 21, 2015 at 20:20 UTC | |
by james28909 (Deacon) on Aug 21, 2015 at 21:21 UTC | |
by poj (Abbot) on Aug 22, 2015 at 19:22 UTC | |
by james28909 (Deacon) on Aug 22, 2015 at 20:03 UTC |