Jeff Westman wrote: > Hi Rob, > > --- Rob Dixon <[EMAIL PROTECTED]> wrote: > > 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. > > This was a totally trivial example of a real world script I am > writing. > > > 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) > > I'm using a fixed number of arguments (2) so this seems to be not > only harder to read, but overkill for a simple list. > > > but it's still a rather odd thing to code! > > It may be more perlish, but I will always have two arguments, so > I'm not really "counting" as it were. I am using it basically to > assign a login ID and a passwd (which unfortunately, are the same, > ie, for security sake). > > > 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. > > Okay, it was a bad example, and I am well aware of $a and $b. As > noted, it was a totally trivial example. Thanks for the advice > though.
Then what you want is: my ($user, $pass) = qw/robdixon secret/; :) Cheers, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]