Hello Masters,
I want to find a pattern in all the files. Then i want to replace an exact specified pattern from every file. I am using the below command. However, the line "s#<--/--a8300-->.*?<--/a8300-->.##isg $_;" gives error. Could you please tell me, how can i use the replace command for all the files. Doesn't perl allow us to give the path of the file which we want to replace. There must be a way in perl and i am waiting for the masters to let us all know how to do that.

Thank You in advance.

#!root/perl5/perlbrew/perls/perl-5.13.4/bin/perl use feature say; #empty the file `>affectedlist.txt;` #will give the list of files which contains the pattern `grep -irl "<--/--a8300-->" ./* >> affectedlist.txt`; open(FILE,"<","affectedlist.txt") or die "Couldn't open file.$!"; foreach (<FILE>) { chomp($_); #Change filenames to unix readable e.g Nayab Rahil to Nayab\ Rahil $_=~ s#\s+#\\ #sg; #replace the pattern on every file. s#<--/--a8300-->.*?<--/a8300-->.##isg $_; #$_ is my filename }

Scalar found where operator expected at final.pl line 11, near
"s#<--/--a8300-->.*?<--/a8300-->.##isg $_"
syntax error at final.pl line 11, near "s#<--/--a8300-->.*?<--/a8300-->.##isg $_"
Execution of final.pl aborted due to compilation errors.

Please help me masters also if you can provide me good links to understand perl pattern matching. It would be really great for us.
Thanks again for your time.


In reply to 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.