Dear Monks

When I print data with my code, I get unexpected results

I stock data in a hash table :

when I try to print my hash table, and make a loop on the keys, instead of seeing all the elements that were pushed in the hash, I see only one per key

Could you tell me why please ?

Here is my code

#!/usr/bin/perl use strict; use warnings; use diagnostics; use Cwd; # input files to work on my $file= "$ARGV[0]"; open INFILE, '<', $file, or die "Can't open $file : $!"; my %aircraftID; while (my $line = <INFILE>){ chomp($line); my @Elements = split ';', $line; # the command shift takes away the first element of the table and +stocks it in a variable my $aircraft_id = shift(@Elements); # the element of the first column (the aircraft_id) has been taken + from Elements # a hash table cannot contain lists # that's why a reference to a list is needed # this reference is called by the antislash \ my $row = \@Elements; push @{$aircraftID{$aircraft_id}}, @{$row}; print STDOUT "la row2 vaut @{$row}\n"; } close INFILE; print STDOUT "\n"; foreach my $cle (keys %aircraftID){ print STDOUT "the value of $cle is : \n"; print STDOUT "@{$aircraftID{$cle}}\n"; }

And here is the file input

DAL11;DAL12;DAL;B772;KATL;EGKK;22:05;1325;05:39;339 SHT8K;SHT9Y;SHT;B752;EGPH;EGLL;18:00;1080;18:55;1135 SHT8K;SHT9P;SHT;B752;EGPH;EGLL;17:42;1062;18:37;1117 SHT8K;SHT9B;SHT;B752;EGPH;EGLL;10:55;655;11:49;709

In reply to reference and hash 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.