Hari7 has asked for the wisdom of the Perl Monks concerning the following question:
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:
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,{few parameters},fwrite(f,{kjg,kk})); $fwrite(f,koal,jirp); fwrite(f,jrei,orowp,jgo);
$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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: A Question on Regex
by davido (Cardinal) on Sep 07, 2011 at 07:55 UTC | |
|
Re: A Question on Regex
by Khen1950fx (Canon) on Sep 07, 2011 at 08:03 UTC | |
|
Re: A Question on Regex
by Anonymous Monk on Sep 07, 2011 at 07:54 UTC | |
|
Re: A Question on Regex
by Utilitarian (Vicar) on Sep 07, 2011 at 10:26 UTC | |
|
Re: A Question on Regex
by Anonymous Monk on Sep 07, 2011 at 08:09 UTC | |
|
Re: A Question on Regex
by bennierounder (Sexton) on Sep 07, 2011 at 08:02 UTC |