On 4/20/10 Tue Apr 20, 2010 11:23 AM, "Marc Perry" <marcperrys...@gmail.com> scribbled:
> 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? You put the left-hand side into list context, which forces the right-hand side of the assignment into list context. Perl will interpolate the scalar value 1 into a list for you, yielding the one-element list (1). The first element of the right-hand side (1) will then be assigned to the first element of the left-hand side ($var). Therefore, you gain nothing except to confuse your readers. That line is better written as: my $var = 1; -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/