- 论坛徽章:
- 0
|
原帖由 UJoe 于 2007-4-18 19:49 发表
my %hash;
$hash{"objA"}{"size"}="ewr";
$hash{"objA"}{"width"}="werwer";
$hash{"objB"}{"size"}="ewasdr" ...
Hi,
this data structure is called hashes of hashes, using reference to hash in hash.
pls read:
perldoc perlref
perldoc perldsc
For example, another writewise:
my %hash = (
objA => {size=>"ewr", width=>"werwer"}, # ref. to hash as value "{}" used
objB => {size=>"ewasdr", width=>"werweasdr"}
);
# to read it:
foreach my $key (keys %hash) {
print "$key => {";
my %val = %{$hash{$key}}; # value is ref. hash and do dereference
foreach my $subkey (keys %val) {
print $subkey . " => " . $val{$subkey} . ",";
}
print "}\n";
}
# call some value directly:
print "objA's size = ", $hash{objA}->{size}, "\n"; |
|