in reply to RE: This should be simple but I cant seem to figure it out
in thread This should be simple but I cant seem to figure it out
If you want to be a sneaky little guy, you could use a positive look-ahead assertion, to avoid having to substitute $marker with something AND $marker:$marker = "<!-- NEW URL HERE -->"; # let's use perl's built-in in-place editing # please check the 'perlrun' documentation for # explanation of the -i switch, and the 'perlvar' # documentation for the corresponding $^I variable { # $^I = "" <-- no backup file # @ARGV = ("foo.html") <-- magical <> works on this file local ($^I, @ARGV) = ("", "foo.html"); while (<>) { # \Q will escape any special regex chars in $marker # if any exist -- good safety measure! s/\Q$marker/$url<BR>\n$marker/; print; } }
Yadda yadda.# stick "$url<BR>" RIGHT BEFORE $marker s/(?=\Q$marker)/$url<BR>\n/;
|
|---|