Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re^2: Assign multiple scalars the same value

by diotalevi (Canon)
on Jan 24, 2005 at 22:55 UTC ( #424730=note: print w/ replies, xml ) Need Help??

in reply to Re: Assign multiple scalars the same value
in thread Assign multiple scalars the same value

This solution is less good than simply assigning the value to each variable separately in my $a = my $b = my $c = 'TRUE' because it avoids having to count how many variables you have. In your code, if you got the number wrong then the trailing variables will be left undefined which is far and away from the intent to leave them with a true value. You're making it easy to write in a bug later.

Comment on Re^2: Assign multiple scalars the same value
Download Code
Replies are listed 'Best First'.
Re^3: Assign multiple scalars the same value
by xdg (Monsignor) on Jan 25, 2005 at 19:44 UTC

    Good point. One could always do this:

    use Want 'howmany'; my ($a, $b, $c) = &{ sub{ (1) x howmany } };

    Not sure if that's shorter/better than other solutions (plus requires Want), but it's another way of keeping the number of variables in sync.


    Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://424730]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2015-10-05 00:17 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (105 votes), past polls