![]() |
|
P is for Practical | |
PerlMonks |
Re: Replace a pattern in each fileby Eily (Prior) |
on Nov 01, 2013 at 12:25 UTC ( #1060754=note: print w/replies, xml ) | Need Help?? |
Adding \ in front of the spaces is not necessary. This is useful in a shell command to show that the space isn't here to separate different arguments if your string isn't enclosed in quotes. But since your file name is in a string of its own, there's no ambiguity. Besides with s#\s+#\\ /sg; you would have replaced multiple spaces by only one. What you are searching for is Inplace Editing, you either have to add the -i option in your shebang (first line) or set the $^I variable. This means that all files opened with the <> construct will be edited inplace. while (<>) will go through each lines of each files in @ARGV (which you can set manually), and with inplace editing activated, anything you will print will be written to that file (so to let a line unchanged, you actually have to print it again).
Maybe what you actually meant is actually s! <--/--a8300--> (.*?) <--/a8300-->. !$1!igr which translate to "get the content of <--/--a8300--> <--/a8300-->and keep only that", when what you wrote will delete the whole thing, tag and content. You could read perlretut for useful information on Perl regexen. Are you sure sed wouldn't have been enough though?
In Section
Seekers of Perl Wisdom
|
|