Thread Daten "Hashen"?
(14 answers)
Opened by gmafx at 2010-11-25 22:39
Versuch es mit einem Hash of Arrays (HoA).
ungetestet: Code (perl): (dl
)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 #!/usr/bin/perl use strict; use warnings; my %elements = (); my $input = $ARGV[0]; my $cnt=0; open (my $fh, '<', $input) or die("ERROR open $input ($!)\n"); while(my $line=<$fh>) { chomp($line); my ($id,@words) = split /\s+/, $line; $elements{$id}=\@words; $cnt++; if ($cnt % 1000000 == 0) {print "read another 1000000 lines!\n";} } close($fh); while( my ($k, $v) = each %elements ) { print "key: $k, value: ".join(', ',@$v).".\n"; } |