Hi, I am working on a script. I need to search for specific string and add two lines below that string. Like this :

This is my file lvtnfet cmos20lpm lvtnfet_b symbol d g s b PROPMAP m=m And this would be my output file lvtnfet_float cmos20lpm lvtnfet_b symbol d g s b PROPMA +P m=m lvtnfet_auxpc2 cmos20lpm lvtnfet_b symbol d g s b PROPM +AP m=m
I am using this code just to test my script :
#!/tool/pandora/.package/perl-5.12.1/libexec/perl5.12.1 -w use strict; use warnings; my $file="device.map"; open (FH, "< $file") || die "Could not open file: $!\n"; my @lines = <FH>; close(FH); open (FH, "> $file"); for (@lines){ if ($_=~m/lvtnfet cmos20lpm lvtnfet_b symbol d g s b PR +OPMAP m=m/) print FH "lvtnfet_float cmos20lpm lvtnfet_b symbol d g +s b PROPMAP m=m \n"; print FH "lvtnfet_auxpc2 cmos20lpm lvtnfet_b symbol d g +s b PROPMAP m=m \n"; } print FH close FH; print "done\n";
I am getting so many errors like these
Bareword found where operator expected at device.map line 4, near "// +GLOBALFOUNDRIES" (Missing operator before GLOBALFOUNDRIES?) Bareword found where operator expected at device.map line 6, near "// +except" (Missing operator before except?) Bareword found where operator expected at device.map line 47, near "m= +m AREA=area" Bareword found where operator expected at device.map line 48, near "m= +m AREA=area"
I hope if someone could help me with that. Thanks.


In reply to Search and add lines into a file. Getting bareword error. by freekngeek

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.