Thread Hashes in Array (4 answers)
Opened by Moritz at 2013-01-09 17:27

FIFO
 2013-01-09 17:46
#164823 #164823
User since
2005-06-01
469 Artikel
BenutzerIn

user image
indem Du die Hashreferenz im Array-Element derefernzierst, z.B. so:

Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
use strict;
use warnings;

my @array;
my %hash = (a => 1, b => 5, c => 11);
$array[1] = \%hash;

print "flat list:\n";

print join("\n",%{$array[1]});

print "\n\nkey-value-pairs:\n";

for my $k (keys %{$array[1]}) {
        print "$k => " . $array[1]->{$k} ."\n";
}


Ausgabe:
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
flat list:
c
11
a
1
b
5

key-value-pairs:
c => 11
a => 1
b => 5
Everyone knows that debugging is twice as hard as writing a program in the first place. So if you're as clever as you can be when you write it, how will you ever debug it? -- Brian Kernighan: "The Elements of Programming Style"

View full thread Hashes in Array