Firstly, the code you've shown isn't going to print anything, let alone the wrong thing. There are a number of variables %count_, $temp, $start_brckt, $end_brckt, %temp_, $cou, and $slack, which have not been declared anywhere, so Perl will kick up a stink at compile-time, and won't even attempt to run your code.

Secondly, it's not clear how you expect to get from your input data to your expected output. The expected output appears to show the numbers -0.50 and 0.2 a lot, but the input data doesn't include them, and you aren't doing any maths in your code except for a ++ which usually implies integer maths. (Though actually in Perl, ++ works on floating point numbers, and strangely, on strings.)

Lastly, you don't seem to have a clear idea of how to go about solving your problem. It looks like you've adopted the approach of diving in and typing stuff and hoping that it works. When it hasn't you've added a few extra braces and dollar signs, crossed your fingers and prayed to whatever deity you believe in!

Step back from the problem. Print out a hard copy of your sample input report on real, actual paper. Get two rulers (no, not these ones), a pencil, and a blank sheet of paper.

Arrange the rulers on the print-out so that you can see a single line of text between them. This is your while loop. It will allow you to step through the file one line at a time without looking ahead or back.

The blank paper and the pencil are your %PG hash.

You are Perl.

While Perl (i.e. you) goes though the input file (i.e. the print-out), it should generate the data structure you want (i.e. you should draw on the blank paper). Think about what features of each line cause what changes to the data structure.

When you've completed that exercise, you should have a much better idea of the algorithm you need to use to generate your data structure. Read perllol and Mini-Tutorial: Dereferencing Syntax to refresh your memory on how nested data structures work in Perl.

Then sit down and code.

In the mean time, here's a nice 3D hash.

use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name

In reply to Re: Hash of hash?? by tobyink
in thread Hash of hash?? by mak.jordan

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.