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

Re: variable declaration question

by MidLifeXis (Monsignor)
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
Replies are listed 'Best First'.
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 cooling their heels in the Monastery: (14)
As of 2015-07-07 22:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (93 votes), past polls