Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

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.


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 all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2018-06-24 19:51 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (126 votes). Check out past polls.