Reference of table of hask
am 08.01.2006 00:23:21 von Lactarius
hi,
I have a table of hash
my @Tab = (
{ cour => '001', heure => '10:20', date =>
'01/01/2006' },
{ cour => '002', heure => '10:20', date =>
'01/01/2006' },
);
and for add elements I want to push new emements in a SUB function. like
this :
addElement(\@Tab);
sub addElement {
my ?????? = shift;
}
How can I declare this variable ?
Thank
Lactarius.
Re: Reference of table of hask
am 08.01.2006 00:58:39 von Gunnar Hjalmarsson
Lactarius wrote:
> I have a table of hash
>
> my @Tab = (
> { cour => '001', heure => '10:20', date =>
> '01/01/2006' },
> { cour => '002', heure => '10:20', date =>
> '01/01/2006' },
> );
More commonly named "array of hashes".
> and for add elements I want to push new emements in a SUB function. like
> this :
> addElement(\@Tab);
>
> sub addElement {
> my ?????? = shift;
> }
First you need something to add. Let's assume you have:
my $element = {
cour => '003',
heure => '10:20',
date => '01/01/2006',
};
Then you can do:
addElement( \@Tab, $element );
sub addElement {
my ($tabref, $element) = @_;
push @$tabref, $element;
}
Suppose you'd better read up on references and data structures.
Suggested reading:
perldoc perlreftut
perldoc perlref
perldoc perldsc
perldoc perllol
Good luck!
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl