RCP has asked for the wisdom of the Perl Monks concerning the following question:

Been awhile since I've been here, but I need some pointers again. I'm trying to extract data from different lines in a report (cwnote) and rewrite it out to another file (circuit_violations.txt), but a test printout (shown below) shows FIRST LINES: only once (should be 4x), while SECOND LINES: do print out the required data. Why isn't the FIRST LINES outputting four lines?

Thanks... RCP

#!perl -w ## ## This file is needed: c:/tmp/cwnote ## perl cw_wires.pl #### BELOW IS A EXAMPLE OF CWNOTE (exclude the pound symbol) #### Error: Trace to Pin violation on BACK with Clearance (0.3) #### Trace (2.97781,39.757),(7.85804,39.757) on Net (GND_SPI) of Size +(0.25) overlaps #### Pin (P101-a4) at (4.05,41.025) on Net (/N$16294) of Size (1.84) ( +from: Idea/LAYOUT/ROUTE 35) ## P101-a4 4.05 41.025 on Net /N$16294 of Size 1.84 from: Idea/LAYOUT +/ROUTE 35 #### Error: Pin to Fill_Area violation on IN2_GND with Clearance (0.3) #### Fill_Area (3.061,-14.425) (379.39,92.965) on Net (GROUND_CHASSIS) + overlaps #### Pin (M200-g7) at (235.89,92.046) on Net (/I$13957/N$1243) of Size + (1.27). (from: Idea/Util/Fill 07) ## M200-g7 235.89 92.046 on Net /I$13957/N$1243 of Size 1.27. from: +Idea/Util/Fill 07 #### Error: Fill_Area to Polygon violation on IN2_GND with Clearance ( +0.38) #### Fill_Area (-8.139,-15.475) (92.384,37.151) on Net (GROUND_CHASSIS +) overlaps #### Polygon with bounds (6.399,-5.228) (10.0989,-3.178). (from: Idea/ +Util/Fill 34) ## Polygon 6.399 -5.228 10.0989 -3.178. from: Idea/Util/Fill 34 #### Error: Trace to Trace violation on FRONT with Clearance (0.25) #### Trace (18.4375,79.2512),(18.7188,78.97) on Net (+3.3V) of Size (0 +.3) overlaps #### Trace (18.169,78.68),(18.169,80.27) on Net (/I$13956/I$68/N$14) o +f Size (0.254) (from: Idea/LAYOUT/ROUTE 32) ## Trace 18.169 78.68 18.169,80.27 on Net /I$13956/I$68/N$14 of S +ize 0.254 from: Idea/LAYOUT/ROUTE 32 open(MYOUTFILE, ">c:/tmp/circuit_violations.txt"); open(MYOUTFILE, ">>c:/tmp/circuit_violations.txt"); open (FILEH, "c:/tmp/cwnote"); while (<FILEH>) { chomp; if (/overlaps/i) { tr/:)(/ /; s/,/ /g; ($xloc,$yloc,$name) = (split)[1,2,7]; print "FIRST LINES: $xloc $yloc $name\n"; while (<FILEH>) { chomp; if (/from/i) { s/\(/ /g; s/\)/ /g; s/Pin/ /g; s/at/ /g; s/,/ /g; s/with/ /g; s/bounds/ /g; ($xloca,$yloca) = (split)[1,2]; print "SECOND LINES: $xloca $yloca\n"; print MYOUTFILE "\$view_area([[($xloca - 1.27), ($yloca - 1.27), 'BO\$ +board'], [($xloca + 1.27), ($yloca + 1.27), 'BO\$board']]);\n"; print MYOUTFILE "\$select_edit_segment([$xloc, $yloc, 'BO\$board']);\n +"; print MYOUTFILE "\$highlight_net_toggle('$name', \@NoRepeat);\n"; print MYOUTFILE "\$suspend();\n"; print MYOUTFILE "\$unselect_all();\n"; print MYOUTFILE "\$unhighlight_nets(\@all);\n"; print MYOUTFILE "\n"; } } } } close(MYOUTFILE);
output
------
FIRST LINES: 2.97781 39.757 GND_SPI
SECOND LINES: 4.05 41.025
SECOND LINES: 235.89 92.046
SECOND LINES: 6.399 -5.228
SECOND LINES: 18.169 78.68

Replies are listed 'Best First'.
Re: Extract and re-write
by Mr_Jon (Monk) on Sep 02, 2004 at 11:56 UTC
    The essential problem is that your inner while <FILEH> loop reads through to the end of the input file, so the outer loop printing "FIRST LINES" only ever executes once. Simply remove this inner read on the filehandle to solve the problem. Indenting the loops helps you see better what is going on.
    while (<DATA>) { chomp; if (/overlaps/i) { tr/:)(/ /; s/,/ /g; ($xloc,$yloc,$name) = (split)[1,2,7]; print STDERR "FIRST LINES: $xloc $yloc $name\n"; } if (/from/i) { s/\(/ /g; s/\)/ /g; s/Pin/ /g; s/at/ /g; s/,/ /g; s/with/ /g; s/bounds/ /g; ($xloca,$yloca) = (split)[1,2]; print STDERR "SECOND LINES: $xloca $yloca\n"; } } __DATA__ Error: Trace to Pin violation on BACK with Clearance (0.3) Trace (2.97781,39.757),(7.85804,39.757) on Net (GND_SPI) of Size (0.25 +) overlaps Pin (P101-a4) at (4.05,41.025) on Net (/N$16294) of Size (1.84) (from: + Idea/LAYOUT/ROUTE 35) P101-a4 4.05 41.025 on Net /N$16294 of Size 1.84 from: Idea/LAYOUT/ROU +TE 35 Error: Pin to Fill_Area violation on IN2_GND with Clearance (0.3) Fill_Area (3.061,-14.425) (379.39,92.965) on Net (GROUND_CHASSIS) over +laps Pin (M200-g7) at (235.89,92.046) on Net (/I$13957/N$1243) of Size (1.2 +7). (from: Idea/Util/Fill 07) M200-g7 235.89 92.046 on Net /I$13957/N$1243 of Size 1.27. from: Idea/ +Util/Fill 07 Error: Fill_Area to Polygon violation on IN2_GND with Clearance (0.38) Fill_Area (-8.139,-15.475) (92.384,37.151) on Net (GROUND_CHASSIS) ove +rlaps Polygon with bounds (6.399,-5.228) (10.0989,-3.178). (from: Idea/Util/ +Fill 34) Polygon 6.399 -5.228 10.0989 -3.178. from: Idea/Util/Fill 34 Error: Trace to Trace violation on FRONT with Clearance (0.25) Trace (18.4375,79.2512),(18.7188,78.97) on Net (+3.3V) of Size (0.3) o +verlaps Trace (18.169,78.68),(18.169,80.27) on Net (/I$13956/I$68/N$14) of Siz +e (0.254) (from: Idea/LAYOUT/ROUTE 32) Trace 18.169 78.68 18.169,80.27 on Net /I$13956/I$68/N$14 of Size +0.254 from: Idea/LAYOUT/ROUTE 32
      Thanks for your help, apparently I forgot some basic programming structuring. RCP
Re: Extract and re-write
by rupesh (Hermit) on Sep 02, 2004 at 12:07 UTC

  • Use strict;
  • Format your code in such a way that you can identify all "{" with all matching "}".
  • Open filehandles in the format  open FH, '<', 'c:\pathoffile\file'; - it reads better.

    Following the above rules would help you immensely in case your code goes wrong.

    Rupesh.