Quick Perl Question....

Bulldog13

Golden Member
Jul 18, 2002
1,655
1
81

'second' => [ 'camel', 'pony' ],
'third' => { 'snake' => 2, 'constrictor' => 1 },


What is the difference between line 'second and line 'third ?

Third uses the curly braces and what looks like an operand... ?

Thanks

Also, can anyone personally recommend a good perl tutorial ? I googled and found a bunch, but just wanted to know if anyone had any personal recommendations.
 

notfred

Lifer
Feb 12, 2001
38,241
4
0
As far as I can tell, both lines should be using plain old parentheses rather than curly or square brackets. What are you trying to do? That's really funky looking code, and even though it'll compile, it looks pretty useless.

What it appears that you're trying to do is define hash elements containing an anonymous array and an anonymous hash, but you'd use parentheses, not brackets.
 

stndn

Golden Member
Mar 10, 2001
1,886
0
0
my %docs = (
'first' => [ 'elephant', 'snake' ],
'second' => [ 'camel', 'pony' ],
'third' => { 'snake' => 2, 'constrictor' => 1 },
);

#######
# Line 1 - Create a hash called docs
# Line 2-4 - The hash will have subscripts called first, second, and third
# For first, it will be reference to array with the contents elephant and snake. Similar with second
# For third, it will be a reference to hash with subscript snake having the value 2 and subscript constrictor having the value 1