Éric Lévénez
2012-05-18 18:36:52 UTC
Hi,
I wish I add an array in a hash table.
A hash is used to get a name using a key,
and another to access an array.
It purpuse of the example is :
. to add 'd' after 'c',
. to display all elements in arrays,
. empty the arrays.
The code bellow doesn't work at all :
#! /usr/bin/perl -w
my %tbl = (
k1 => { name => 'n1', list => ('a', 'b', 'c') },
k2 => { name => 'n2', list => () },
k3 => { name => 'n3', list => ('e') }
);
my $key = 'k1';
push @tbl{$key}{list}, 'd';
foreach $key (keys %tbl) {
my $name = $tbl{$key}{name};
print "Name of $key : $name\n";
print "list:\n"
foreach $i (@tbl{$key}{list}) {
print "$i\n";
}
@tbl{$key}{list} = ();
}
I wish I add an array in a hash table.
A hash is used to get a name using a key,
and another to access an array.
It purpuse of the example is :
. to add 'd' after 'c',
. to display all elements in arrays,
. empty the arrays.
The code bellow doesn't work at all :
#! /usr/bin/perl -w
my %tbl = (
k1 => { name => 'n1', list => ('a', 'b', 'c') },
k2 => { name => 'n2', list => () },
k3 => { name => 'n3', list => ('e') }
);
my $key = 'k1';
push @tbl{$key}{list}, 'd';
foreach $key (keys %tbl) {
my $name = $tbl{$key}{name};
print "Name of $key : $name\n";
print "list:\n"
foreach $i (@tbl{$key}{list}) {
print "$i\n";
}
@tbl{$key}{list} = ();
}
--
Eric
Eric