Janek Schleicher wrote:
> Paul D. Kraus wrote at Thu, 17 Jul 2003 15:33:11 -0400:
>
> > Is there a way to assign a single value to a list? other then
> > doing the obvious and spelling out each list assignment or
> > running through a loop.
> >
> > For instance...
> >
> > my ( $var1, $var2, $var3, ... ) = "Paul"
> > assigning paul to all variables in the list.
> >
> > or a more useful example
> >
> > my ($passed1, $passed2, ... ) = shift
>
>
> As you know how many items are on the left side of the list,
> you can use the x operator:
>
> my ( $var1, $var2, $var3, $var4 ) = ("Paul") x 4;
>
> That works the same with shift.
> But note that in this way, $passed1 would be equal to $passed2 and
> so on
>
> If you wanted to have $passed1 with the first passed argument,
> $passed2 with the second one and so on,
> you should use the @_ array directly:
>
> my ($passed1, $passed2, $passed3 ) = @_;
>
>
> BTW: If you would have an array instead of a list at the left side,
> everything becomes easier:
> $_ = "a value" foreach @array;
This works with a list Janek, and would be my preferred solution.
$_ = 'Paul' foreach my ( $var1, $var2, $var3, $var4 );
But note, Paul, that your second example is very different from
your first. Copying a subroutine's parameters into a number
of scalar variables is done just as Kanek hash said. This is
a standard Perl idiom.
HTH,
Rob
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]