Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^2: variable declaration question

by 7stud (Deacon)
on Jan 18, 2013 at 22:08 UTC ( #1014142=note: print w/ replies, xml ) Need Help??


in reply to Re: variable declaration question
in thread variable declaration question

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.


Comment on Re^2: variable declaration question
Select or Download Code
Re^3: variable declaration question
by keszler (Priest) on Jan 18, 2013 at 22:14 UTC
    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://1014142]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2014-07-10 04:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

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








    Results (198 votes), past polls