P
Paul Lalli
Oobi said:Could someone please brief me a little on arrays and hashes.
You should REALLY REALLY read a decent tutorial on Perl for these sorts
of questions. I recommend starting in this case with
http://perldoc.perl.org/perldata.html
For example:
What is the difference with () and {}?
Parentheses are (usually) used to construct a list, which is used to
populate an array or a hash:
my @array = (1, 2, 3, 4);
my %hash = (one => 1, two => 2, three => 3);
Curly-braces have a variety of functions in Perl. They are used to
access a specific value of a hash by enclosing a key:
$hash{four} = 4;
They are used to create an anonymous hash reference:
my $hash_ref = { one => 1, two => 2, three => 3 } ;
The are also used to create blocks and subroutines, as well as delimit
a variable name inside a double-quoted string. There are other uses as
well, but I don't think they apply to your question.
also:
do I need to enclose each element in an array with []?
No. Brackets, like braces, have multiple functions. They are used to
access a specific element from an array, by enclosing an index:
$array[2] = 20;
They are also used to create an anonymous array reference:
my $array_ref = [ 1, 2, 3, 4];
I am trying to construct an array of hashes.
You need to read a decent tutorial or two about this too.
http://perldoc.perl.org/perlreftut.html
http://perldoc.perl.org/perllol.html
http://perldoc.perl.org/perldsc.html
http://perldoc.perl.org/perlref.html
All is good but iterating over
the array there is only one element*S*...and iterating over the element
gives me the hash array*S*. ...
this is what i have
my @ary=
[
{
},
...
{
},
];
This creates an array that contains exactly one element. That one
element is a reference to an anonymous array. That anonymous array
contains multiple references to anonymous hashes.
Changing the outer [ ] to ( ) will be a good start, but you really need
to read those Perldocs to understand multi-level structures in Perl.
Paul Lalli