For Programmers: Free Programming Magazines  


Home > Archive > PERL Programming > January 2006 > Reference of table of hask









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Reference of table of hask
Lactarius

2006-01-10, 4:03 am

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.




Gunnar Hjalmarsson

2006-01-10, 4:03 am

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
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com