develooper Front page | perl.beginners | Postings from April 2010

What is the difference between: 'my $var = 1' vs. 'my ( $var ) = 1'?

Thread Next
From:
Marc Perry
Date:
April 20, 2010 11:23
Subject:
What is the difference between: 'my $var = 1' vs. 'my ( $var ) = 1'?
Message ID:
u2pb90a197e1004201123v15abdfc4w5d01be64a45296c@mail.gmail.com
At the introductory level it seems like I have often seen code like this:

use strict;

my $var = 1;

And as I review other peoples' scripts I have often encountered code like
this:

use strict;

my ( $this, $that, $the_other );

Which I interpreted as a mechanism to declare a number of scalar variables
with a minimum of typing.  But lately I've been seeing this syntax and I was
wondering if it was fundamentally different (and somehow more desirable):

use strict;

my ( $var ) = 1;

As if $var is being declared in a list context; what, if anything, do I get
by including parentheses when declaring a single variable?

Thanks,

--Marc

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About