Here is my perl file:
#!usr/bin/perl # # $verno = 1.0; $max_iter = 4; $max_y_locations = $max_iter; $y_iter_max = 0; $x_iter_max = 0; # Note:0 counts as one iteration $z_iter_max = 0; # $no_energy_bins = 97; # 98 bins - [0:97 +] @spec_cps = [$no_energy_bins],[$max_y_locations]; @sigma_cps = [$no_energy_bins],[$max_y_locations]; $spec_cps [$no_energy_bins] [$max_y_locations] = 0.0; $sigma_cps[$no_energy_bins] [$max_y_locations] = 0.0; # . . . . # do { $y_iter_no = $y_iter_no + 1; $new_y = $y_old + $del_y * ($y_iter_no - 1); $x_iter_no = 0; open (OUT, "<$out_file") or die "Cannot open $out_file for readin +g: $+!"; while (<OUT>) { next unless $_; if ($_ && /1tally\s\s(\d+)\s+nps\s=/i) { for (my $ii = 0; $ii < 5; $ii++) { } } for (my $ij = 0; $ij < 98; $ij++) { if ($_ && /\s\s\s(\d+).(\d+)(\D+)(\d+)\s\s\s(\d+).(\d+)(\D+)( +\d+)\s(\d+).(\d+)/i) { $energy_value = $1.$dot.$2.$3.$4; $detector_value = $5.$dot.$6.$7.$8; $std_deviation = $9.$dot.$10; $kebin=$ij; print "kebin=$kebin\n"; print "energy=$energy_value\n"; print "detvalue=$detector_value\n"; print "sigma=$std_deviation\n"; $energy_bin[$kebin] = $energy_value; $spec_cps[$kebin][$y_iter_no] = $detector_value; $sigma_cps[$kebin][$y_iter_no] = $std_deviation; } } } # close (OUT); # print "y=$new_y\n"; print "z=$new_z\n"; print "x=$new_x\n"; print "kount=$kount\n"; $kount = $kount + 1; # # printf PLOUT ("%.3f %.5e %.5f \n",$new_y,$detector_value,$std_de +viation,); # } until $z_iter_no > $z_iter_max; # } until $x_iter_no > $x_iter_max; # } until $y_iter_no > $y_iter_max; # for ( my $i = 0; $i < 97; $i++) { for ( my $j = 0; $j < $max_y_locations; $j++ ) { printf PLOUT ("%.3f %.5e %.5e \n", # printf PLOUT (" \n", $energy_bin[$i],$spec_cps[$i],[$j],$sigma_cps[$i +],[$j] ) ; } } # close (PLOUT);
Here is the data file I am trying to read:
. . . 1tally 18 nps = 3785697 tally type 8 pulse height distribution. + units number tally for photons cell 3 energy 0.0000E+00 0.00000E+00 0.0000 1.0000E-05 2.64152E-07 1.0000 5.0000E-02 0.00000E+00 0.0000 6.0000E-02 0.00000E+00 0.0000 7.0000E-02 0.00000E+00 0.0000 8.0000E-02 0.00000E+00 0.0000 9.0000E-02 0.00000E+00 0.0000 1.0000E-01 0.00000E+00 0.0000 . . . 9.7000E-01 0.00000E+00 0.0000 9.8000E-01 0.00000E+00 0.0000 9.9000E-01 0.00000E+00 0.0000 1.0000E+00 0.00000E+00 0.0000 total 5.28304E-07 0.7071
So I am trying to read the three columns after energy and before total.
I did this by locating the 1tally line and skipping 5 lines, or so I thought.
What the %&&!^^@@* am I doing wrong?
I know I am making this a lot harder than necessary.

The print statements are just for debugging.
The portion of code of interest in between the open out and close out statements.
Thanks in advance for any tips,
Bruce

Edit: g0n - readmore tags


In reply to Reading column data from a file by pattobw

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.