Dear Monks, I think I may need a hash of hashes for my program. Could you confirm it ?

In the input data, I have a list of airports (first column) their departure time (second column) and ID (third column). I would like to reorganize the flights so they depart from each airport with their departure time equally distributed per hour

Here is the code

#! perl -slw use strict; use diagnostics; use Data::Dump qw[ pp ]; my %in; my %former_in; my %airport_hash; # first select and the data whether the airport is AAAA or BBBB while (<DATA>){ $_ =~ s/\s+$//; m[^(\w\w\w\w)] and push @{$airport_hash{$1}}, $_; } foreach my $airport ( keys %airport_hash){ my @lines = @{$airport_hash{$airport}}; foreach my $line(@lines){ # print STDOUT "line is $line"; if ($line =~ /(\w\w\w\w\s)(\d\d):(\d\d) (.+)/){ push @{ $in{ $2 } }, $line and $former_in{$line} = $3; print STDOUT "1 is $1"; # print STDOUT "2 is $2"; # print STDOUT "3 is $3"; # print STDOUT "4 is $4"; } } for my $hr ( sort{ $a <=> $b } keys %in ) { my $n = $#{ $in{ $hr } }; my $step = 60 / $n; my $min = 0; for my $flight ( @{ $in{ $hr } } ) { my $former_time = $former_in{$flight}; # relative difference my $diff = int( $min ) - $former_in{$flight}; printf( "%02d:%02d %s %s\n", $hr, int( $min ), $flight, $d +iff ); $min += $step; $min = 59 if $min > 59; } } } # AAAA and BBBB represent two airports __DATA__ AAAA 11:01 A1 AAAA 11:03 A3 BBBB 11:10 B4 AAAA 11:30 C4 AAAA 11:30 C6 BBBB 11:50 D5 AAAA 12:01 E15 AAAA 12:01 F16 BBBB 12:02 G6 BBBB 12:25 H2 BBBB 12:27 Z6 BBBB 12:27 Y2 AAAA 12:25 I8 BBBB 12:30 J3 AAAA 12:30 K7 BBBB 12:50 L15 AAAA 12:55 M16

The problem is that for the second case of airport (BBBB), the hash %in still takes into account the AAAA lines so the computation is made with the AAAA flights.. That's why I think I may need a hash of hash but I do not know how to build one.


In reply to hash of hashes maybe needed by steph_bow

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.