On 10/9/07, Chas. Owens <[EMAIL PROTECTED]> wrote:
> On 10/9/07, yitzle <[EMAIL PROTECTED]> wrote:
> > On 10/9/07, Beginner <[EMAIL PROTECTED]> wrote:
> > > Can someone explain why there is a 4th, undefined variable being
> > > declared in test? It appears to work it too.
> > >
> > > sub test {
> > >  my ($function, $description, $var) = @_
> > > ...
> > >
> > > I'm sure there is a reason for it but I can't see it.
> > > Thanx,
> > > Dp.
> >
> > No real reason... If you pass extra variables to test, in your version
> > it will assign the list of variables to $var. In my version, it will
> > assign the 3rd parameter to $var and drop the rest.
> snip
>
> No, it doesn't.  That is a list assignment.  The first variable on the
> left gets the first value on the right, the second the second, and so
> on.  Any unused values on the right are discarded.  An undef at the
> end of the list on the left is pointless (if used at the beginning or
> the middle it skips the corresponding value on the right).
>
> #!/usr/bin/perl
>
> use strict;
> use warnings;
>
> my @a = 1 .. 6;
> my ($x, $y, $z, undef) = @a;
> my ($i, $j, $k) = @a;
>
> print "x $x y $y z $z\n";
> print "i $i j $j k $k\n";
>

Oh... Oops. :D Live and learn.

Thanks!

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to