Well you probably want to read perlreftut but how about this:

my ($location, $h); while(<DATA>){ chomp; $location = $_ if m/^[a-zA-Z]/; next unless m/(\d+)\s+(\d+)/; $h->{$location}->{windows}++; $h->{$location}->{frames}->{"$1x$2"}++; $h->{$location}->{total_length}+= $1*2 + $2*2; } use Data::Dumper; print Dumper $h; my $fixed_cost_per_window = 100; my $cost_by_material = 0.5; my $total; for my $location( keys %$h ) { my $fixed = $h->{$location}->{windows} * $fixed_cost_per_window; my $materials = $h->{$location}->{total_length} * $cost_by_materia +l; printf "%-10s\t%d windows \$%7.2f\tmaterials \$%7.2f\ttotal \$%7.2 +f\n", $location, $h->{$location}->{windows}, $fixed, $materials, $fi +xed+$materials; $total += $fixed+$materials; } printf "\nTotal: \$%.2f\n", $total; __DATA__ office 1 120 120 120 120 140 135 155 135 120 120 bedroom 2 100 75 100 75 120 180

This produces:

$VAR1 = { 'bedroom 2' => { 'frames' => { '120x180' => '1', '100x75' => '2' }, 'windows' => '3', 'total_length' => '1300' }, 'office 1' => { 'frames' => { '155x135' => '1', '140x135' => '1', '120x120' => '3' }, 'windows' => '5', 'total_length' => '2570' } }; bedroom 2 3 windows $ 300.00 materials $ 650.00 total $ 950. +00 office 1 5 windows $ 500.00 materials $1285.00 total $1785. +00 Total: $2735.00

cheers

tachyon


In reply to Re: Data Structures Help by tachyon
in thread Data Structures Help by Anonymous Monk

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.