To add what Chas mentioned, it also changes the context of the expression.

One good example is the localtime() function.  In "scalar" context it
returns a date string, and in "list" context it returns a list of the date
parts.  When you use the parens on the left side of the assignment you are
forcing list context.

Try these two bits of code and see the difference in the output:

my $x = localtime;
print $x;

my ($x) = localtime;
print $x;

Rob


-----Original Message-----
From: Chas Owens [mailto:[EMAIL PROTECTED]]
Sent: Monday, May 13, 2002 6:11 PM
To: Scott Lutz
Cc: Beginners (E-mail)
Subject: Re: Different ways of declaring variables


On Mon, 2002-05-13 at 18:07, Scott Lutz wrote:
> I am wondering about the different ways of initializing a single scalar.
> 
> usual method:
> my $variable;
> 
> but I am trying to get what (if anything) is being done differently by
> this :
> my ($variable);
> 
> Thanks!
> 
> 
> Scott Lutz
> Pacific Online Support
> Phone: 604.638.6010
> Fax: 604.638.6020
> Toll Free: 1.877.503.9870
> http://www.paconline.net

The parentheses allow you to declare more than one variable at a time
like this:

my ($id, $name, $age);

They also allow you to do a list assignment (instead of a scalar
assignment) like this:

my ($id, $name, $age) = $sth->fetchrow_array;
 
-- 
Today is Pungenday the 60th day of Discord in the YOLD 3168


Missile Address: 33:48:3.521N  84:23:34.786W


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to