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

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.


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.

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

        Quite right. ++


Log In?

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (11)
As of 2016-02-06 16:31 GMT
Find Nodes?
    Voting Booth?

    How many photographs, souvenirs, artworks, trophies or other decorative objects are displayed in your home?

    Results (233 votes), past polls