steph_bow has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: reference and hash
by moritz (Cardinal) on Aug 22, 2007 at 09:41 UTC | |
|
Re: reference and hash
by FunkyMonk (Bishop) on Aug 22, 2007 at 09:43 UTC | |
by steph_bow (Pilgrim) on Aug 22, 2007 at 09:50 UTC | |
|
Re: reference and hash
by Razvanica (Novice) on Aug 22, 2007 at 09:57 UTC |