Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^3: -> Is Optional ?

by Athanasius (Archbishop)
on Dec 29, 2012 at 16:34 UTC ( [id://1010827]=note: print w/replies, xml ) Need Help??


in reply to Re^2: -> Is Optional ?
in thread -> Is Optional ?

The line

my @a = [ 1, 4, 9, 16 ]; # squares

creates an anonymous array with 4 elements, and assigns a reference to this anonymous array — i.e., a single, scalar value — to be the first (and only) element of the named array @a.

I suspect that parentheses were intended rather than square brackets:

my @a = ( 1, 4, 9, 16 ); # squares my @b = ( 1, 8, 27, 64 ); # cubes my @c = ( \@a, \@b ); # two arrays

and then the rest of the original code behaves as intended.

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1010827]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2024-04-19 20:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found