Jeff Westman wrote: > --- George Schlossnagle <[EMAIL PROTECTED]> wrote: > > > > On Wednesday, June 4, 2003, at 02:40 PM, Wagner, David --- Senior > > Programmer Analyst --- WGO wrote: > > > > > Jeff Westman wrote: > > > > This may sound trivial, but I am trying to declare and assign > > > > multiple scalars to the same variable in the same statement. > > > > This is what I have: > > > > > > > > #!/bin/perl -w > > > > $a = $b = "apple"; # works > > > > use strict; > > > > my ($a = $b) = "apple"; # does not works > > > do: > > > my ($a,$b) = ("apple", "apple"); > > > > or > > > > my ($a, $b) = ("apple")x2; > > > > I like this solution! Cool.... > > Thanks George and David.
I presume this was an exercise, as I don't see any reason to confine youself to your rules otherwise. I think both replies were a little tongue-in-cheek, but I don't like either very much. The first one relies on manually programming the same assigned value twice, and the second one needs you to count the number of variables. These are both things that the language should be doing for you. Much more Perlish is $_ = 'apple' foreach my ($x, $y) but it's still a rather odd thing to code! Oh, and I'm surpised nobody's jumped in yet to say that you shouldn't be using $a and $b anyway. They are variables that are used implicitly by 'sort' and are automatically predeclared as package variables for you. For this reason they're not picked up by 'use strict "vars"' so they are best avoided. Cheers, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]