in reply to Regex stored in a scalar
$line =~ /$regex/;
is a substitution operator, it is not a regex. Only the part between the first two slashes is a regex, not the rest.s/\),\(/\)\n\(/
So if you want to make substitutions you probably want to capture two inputs from the user or from the command line, the searched pattern and the substitution (not tested).
And for a big file, you might want to add the o modifier, it may be faster (but that may depend on your version of Perl).my $regex = <STDIN>; chomp $regex; my $subst = <STDIN>; chomp $subst; while (<INPUTFILE>) { my $line = $_; s/$regex/$subst/gi; }
Update: Oh, BTW, if you're used to do it in vi, you might consider sed. You should feel at home.
Update 2: I crossed out the first part of my answer, as it was at least very incomplete, as kindly pointed out by AnomalousMonk. Only the second part was really relevant to the OP problem.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Regex stored in a scalar
by kroach (Pilgrim) on Aug 22, 2015 at 10:49 UTC | |
by Laurent_R (Canon) on Aug 22, 2015 at 11:35 UTC | |
|
Re^2: Regex stored in a scalar
by AnomalousMonk (Archbishop) on Aug 22, 2015 at 14:34 UTC | |
by Laurent_R (Canon) on Aug 22, 2015 at 16:17 UTC | |
|
Re^2: Regex stored in a scalar
by girarde (Hermit) on Aug 22, 2015 at 14:33 UTC | |
by Laurent_R (Canon) on Aug 22, 2015 at 16:32 UTC | |
|
Re^2: Regex stored in a scalar
by itsscott (Sexton) on Aug 25, 2015 at 02:53 UTC | |
|
Re^2: Regex stored in a scalar
by poj (Abbot) on Aug 22, 2015 at 16:35 UTC | |
by Laurent_R (Canon) on Aug 22, 2015 at 17:02 UTC | |
by AnomalousMonk (Archbishop) on Aug 22, 2015 at 18:15 UTC | |
by Laurent_R (Canon) on Aug 22, 2015 at 18:53 UTC |