Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: variable declaration question

by MidLifeXis (Prior)
on Jan 18, 2013 at 21:04 UTC ( #1014125=note: print w/ replies, xml ) Need Help??


in reply to variable declaration question

To add to what tobyink said, "none" - in context.

my $foo = @some_array_value and my ($foo) = @some_array_value will give two very different results.

print(my $foo = (1, 2, 3), "\n"); print(my ($foo) = (1, 2, 3), "\n"); __END__ 3 1

Update: Alright, either QuickDraw McGraw updated his node, or I skipped over the second and following line when I read it. :-) We stated basically the same thing.

--MidLifeXis


Comment on Re: variable declaration question
Select or Download Code
Re^2: variable declaration question
by tobyink (Abbot) on Jan 18, 2013 at 21:19 UTC

    I updated. It was an afterthought as it didn't seem relevant to the question. (The question included semicolons after the declaration, so the variable is not being initialized.)

    perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
Re^2: variable declaration question
by 7stud (Deacon) on Jan 18, 2013 at 22:08 UTC
    print(my $foo = (1, 2, 3), "\n"); print(my ($foo) = (1, 2, 3), "\n"); __END__ 3 1

    Ah, I see. The line:

    print(my $foo = (1, 2, 3), "\n");

    is a convenient way of assigning the last element of an array to a variable.

      Try:
      print(my $foo = ('a', 'b', 'c'), "\n");
      vs:
      my @foo = ('a', 'b', 'c'); my $bar = @foo; print $bar, "\n";
      I like using letters vs numbers to avoid confusion...

        Quite right. ++

        --MidLifeXis

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (7)
As of 2014-07-14 09:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (257 votes), past polls