in reply to Re: Slurping search-replace patterns from a file
in thread RESOLVED: Slurping search-replace patterns from a file
Unfortunately, this is rather fragile - if "$repl" contains, say, a double quote, it breaks. My solution is somewhat similar, but it uses an actual "eval" so I can catch/warn about the errors:
#!/usr/bin/perl -w use strict; while (<DATA>) { next unless /^\s*s\//; # Minimal checking chomp; my ($pat, $repl) = (split '/') [1, 2]; my $s = "foo"; eval "\$s =~ s/$pat/$repl/"; warn "Warning: $@" if $@; print "$s\n"; } __DATA__ s/foo/bar/ s/(fo)o/bar$1/
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Slurping search-replace patterns from a file
by moritz (Cardinal) on Oct 14, 2008 at 15:49 UTC | |
by HKS (Acolyte) on Oct 14, 2008 at 16:01 UTC | |
by JavaFan (Canon) on Oct 14, 2008 at 16:07 UTC |