Hi Everyone,

I am a Newbie and would like to know how I could do the following regex( really tried for half a day before posting this):

I need to parse a hardware code to pick and choose just the statements starting with "$fwrite(" and that ends with a ";". The coding has new-lines in between those statements, However I want them to be chosen too There are accidental "\n" in between the arguments of $fwrite which should be considered as a single line. When I tried doing :

#!/usr/local/bin/perl -w use strict; open(IN,"<ab.in"); while($_=<IN>) { if($_=~/\$display(.*?);$/i) { print; } } close(IN);

I get statements that have nested "fwrite" statements omitted in the o/p.

Eg. For the statement below:

$fwrite(f,{few parameters},$fwrite(f,{kjg,kk})); $fwrite(f,koal,jirp); fwrite(f,jrei, orowp,jgo);
the o/p is supposed to be:
$fwrite(f,{few parameters},fwrite(f,{kjg,kk})); $fwrite(f,koal,jirp); fwrite(f,jrei,orowp,jgo);
But the o/p that my code is producing instead is

$fwrite(f,koal, jirp);

In short, it is not recognizing fwrite statements that either have: a. a '\n' between its arguments b. nested fwrites.

Hope this is clear.. Can anybody please suggest a better solution.

Thanks, Hari


In reply to A Question on Regex by Hari7

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.