# Is \$A = \$B = n; valid? - Page 2

•  Subject
• Author
• Posted on

## Re: Is \$A = \$B = n; valid?

David Canzi wrote:

Thanks. This begs the question 'what if the variables are intended to be
global?'
--
Joey

## Re: Is \$A = \$B = n; valid?

Then declare them to be global:

perl -c -Mstrict -Mwarnings -e 'our \$A = our \$B = our \$C = 42'

--
Rest In Peace:
Jonah McClellan gave his life for his country in a
helicopter crash in Afghanistan on September 21,2010.
Please pray for his wife and three children.

Doh! Thanks.
--
Joey

## Re: Is \$A = \$B = n; valid?

If you didn't know that, then you would probably benefit from reading:

"Coping with Scoping":

http://perl.plover.com/FAQs/Namespaces.html

--
Rest In Peace:
Jonah McClellan gave his life for his country in a
helicopter crash in Afghanistan on September 21,2010.
Please pray for his wife and three children.

## Re: Is \$A = \$B = n; valid?

On 2010-09-28 00:11, Joey@still_Learning.invalid wrote:

I would not use capital letters for variable names, but further it looks
ok to me.

#!/usr/bin/perl -w
use strict;

sub number { 42 }

my \$foo = my \$bar = my \$baz = number;

__END__

--
Ruud

## Re: Is \$A = \$B = n; valid?

While perfectly fine, I would probably write this as

my (\$foo, \$bar, \$baz) = (number) x 3;

But I'm not sure it has ever come up in my code before. The situation
where you would need to store a variable in a local variable and a
more global hash is much more common, like in the Catalyst example.

//Makholm

## Re: Is \$A = \$B = n; valid?

Peter Makholm wrote:

\$_ = number for my ( \$foo, \$bar, \$baz );

John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction.                   -- Albert Einstein

## Re: Is \$A = \$B = n; valid?

On 2010-09-29 03:53, John W. Krahn wrote:

{   my \$i = 42;
sub number { ++\$i }
}

--
Ruud

## Re: Is \$A = \$B = n; valid?

Dr.Ruud wrote:

Why the overhead of a subroutine call?  Just use a macro which gets
removed at compile time:

sub number () { 42 };

my \$foo = my \$bar = my \$baz = number;

Or:

use constant number => 42;

my \$foo = my \$bar = my \$baz = number;

John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction.                   -- Albert Einstein

## Re: Is \$A = \$B = n; valid?

My guess is that this is just an example and not real production ready
code.

//Makholm