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).

chomp(@ARGV = <FILE>); # put each line of FILE into @ARGV and remove t +he trailing \n while(<>) # for each filename in @ARGV { print s! <--/--a8300--> .*? <--/a8300-->. !!igr; }

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 reply to Re: Replace a pattern in each file by Eily
in thread Replace a pattern in each file by nayabrahil

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.