Greetings All,

This is my first posting/question. I am an ancient computer guy (punch cards and hand-wiring sort boards!) but relatively new to Perl.

Why does the line of code (65 or so lines below):
>>>>> foreach $hr (sort keys %{$ClubTotal ... <<<<<
not work? It does not sort, it does not appear to access the 'bottom key', it does not return anything to $hr (I understand/realize that a list should be returned from 'sort keys').

Can I - using 'only' my code access/retrieve all the data from %ClubTotal? Or, must I use Data::Walk or Data::Visitor or something similiar?

Many, many thanks for sharing your knowledge.

Thomas

* * * Begin program:
* * * Do some preprocessing of input data file, then process * * *
* * * 50,000+ lines of data that we are interested in: * * *
* * * Time of day by halfhour when a patron signs-in at club * * *

* * * This code builds the HASH: %ClubTotal * * *

$dataChunk = substr($_, 42, 17); # yields >06/05/2008 8:31a< from $_ if ($dataChunk =~ m|\d\d/\d\d/\d\d|) { $date = substr($dataChunk, 3, 2); # get date $hour = substr($dataChunk, 11, 2); # get hour $minute = substr($dataChunk, 14, 2); # get minutes $ampm = substr($dataChunk, 16, 1); # get am or pm if (($ampm eq "a") && ($hour <= 9)) {$hour = '0'.int($hour) ; } if (($ampm eq "p") && ($hour != 12)) {$hour = $hour + 12; } $ClubTotal{ 'DayOfMonth'=> $date }{'Date'} = $date ; $ClubTotal{ 'DayOfMonth'=> $date }{'TotalPerDay'} += 1 ; $ClubTotal{ 'DayOfMonth'=> $date }{ 'HourSignIn' => $hour }{'Hour'} += $hour ; $ClubTotal{ 'DayOfMonth'=> $date }{ 'HourSignIn' => $hour }{'TotPerH +our'} += 1 ; if ($minute <= 29) { $ClubTotal{ 'DayOfMonth'=> $date }->{ 'HourSignIn' => $hour }->{'H +alfHour00'} += 1 ; } else { $ClubTotal{ 'DayOfMonth'=> $date }->{ 'HourSignIn' => $hour }->{'H +alfHour30'} += 1 ; } #* * * Do some extra stuff here, finished with input file * * * #* * * Call: sub SortBuildOutput{ * * * sub SortBuildOutput{ #%ClubTotal hash #DayOfMonthxx hash #HourSignInxx hash #TotPerHour scalar #HalfHour00 scalar #HalfHour30 scalar #Hour scalar my $day; my $hr; my @hr; foreach $day (sort keys %ClubTotal) { >>>>> foreach $hr (sort keys %{$ClubTotal{'$day'}{'HourSignIn'} } ) { + <<<<< print $ClubTotal{$day}->{'Date'} . ": " . $ClubTotal{$day}->{'To +talPerDay'} . "\n"; # This TASK: Aggregate Data for end of month summary: # %ClubTotal = ( # 'DayOfMonth26' => { # 'HourSignIn13' => { # 'HalfHour30' => 7, # 'Hour' => 13, # 'HalfHour00' => 11, # 'TotPerHour' => 18 # } # } # to build a record for input to a spreadsheet } # END: foreach my $hr (sort keys %{$ClubTotal{'$day'}{HourSignI +n}}) { } # END: foreach my $day (sort keys %ClubTotal) { } #END: sub SortBuildOutput{
Data::Dumper produces:
%ClubTotal = ( 'DayOfMonth26' => { 'HourSignIn13' => { 'HalfHour30' => 13, 'Hour' => 13, 'HalfHour00' => 10, 'TotPerHour' => 23 }, 'HourSignIn12' => { 'HalfHour30' => 6, 'Hour' => 12, 'HalfHour00' => 8, 'TotPerHour' => 14 }, 'HourSignIn10' => { 'HalfHour30' => 20, 'Hour' => 10, 'HalfHour00' => 19, 'TotPerHour' => 39 'TotalPerDay' => 251, 'Date' => '26', 'DayOfMonth11' => { 'HourSignIn13' => { 'HalfHour30' => 7, 'Hour' => 13, 'HalfHour00' => 11, 'TotPerHour' => 18 }, 'HourSignIn10' => { 'HalfHour30' => 12, 'Hour' => 10, 'HalfHour00' => 11, 'TotPerHour' => 23 },

and so on for all 30 days of the month to produce cumulative totals of all data/scalar items.


In reply to Brain muchly befuddled by nested hashes by WartHog369

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.