Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: simple array question

by philipbailey (Chaplain)
on Jan 03, 2011 at 03:22 UTC ( #880122=note: print w/replies, xml ) Need Help??


in reply to simple array question

It seems that you are trying to assign a list to array @compass. Lists are surrounded by brackets, or parentheses if you prefer that term: (). Instead, you have used braces, which in this case create a reference to an anonymous hash, hence the warning messages.

So you need something more like this:

#!/usr/bin/perl use strict; use warnings; my @compass = ( ["NW", "N", "NE"], ["W", "center", "E"], ["SW", "S", "SE"], ); print $compass[0]->[1];

Replies are listed 'Best First'.
Re^2: simple array question
by chromatic (Archbishop) on Jan 03, 2011 at 04:37 UTC
    Lists are surrounded by brackets....

    Not rvalue lists! Commas, not parentheses, produce literal rvalue lists. The three array references in this variant of that code are a list just as much as in the original version:

    my @compass = ["NW", "N", "NE"], ["W", "center", "E"], ["SW", "S", "SE"], ;

    The difference between the two examples is the precedence of the assignment operator compared to the precedence of the comma operators.

Re^2: simple array question
by tw (Acolyte) on Jan 03, 2011 at 03:40 UTC

    thanks greatly that worked!

    it is nice to have some help when starting, may have been a while before I finally got it.

    seems that some code has { or [ also

    is that a typo or a perl version thing or OS thing or am I still missing something? thanks again

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://880122]
help
Chatterbox?
[1nickt]: This is less than perfect ... but demanding perfection (from people or from life) is a sure way to unhappiness.
[Discipulus]: and anyway we have CB where every (democratic) opinion can be expressed
erix eat the rich!
[1nickt]: I do think it is sad that roho has received 3 downvotes for his polite request, as did I when I objected to the profanity in stonecolddevin's sig. I upvoted both him and Karl for the discussion. Way too much downvoting for inappropriate reasons here!
Discipulus learn that 'argue' has a little negative sense, he thought was a neutral sense, 'vox media'
[1nickt]: argue == discuss && argue == be contentious
[Discipulus]: you are right 1nickt i didnt voted nor downvoted; I just upvote perl content i like
[1nickt]: In Spanish, to argue (like a fight) is discutir -- does not mean to discuss !
[1nickt]: Sigh, this is why I gave up human-only languages and became a Perl linguist :-)
[Discipulus]: i just, rarely, downvote unpolite posts and spam, and wrong advices

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2017-06-22 12:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many monitors do you use while coding?















    Results (519 votes). Check out past polls.