From:Bryan R Harris <[EMAIL PROTECTED]>
> Jenda wrote:
> > From: Bryan R Harris <[EMAIL PROTECTED]>
> >> It makes more sense to me that (<FILE>,<FILE>) is kind of the same thing as
> >> saying (@a,@b).  In list context @a returns the array as a list, but in
> >> scalar context @a returns the number of elements.  Obviously (@a,@b) 
> >> returns
> >> the union of the two lists, not two scalars.  "<FILE>" is treated the same
> >> way.
> > 
> > Almost. It still depends on the left hand side. Try this:
> > 
> > @a = (10,20,30);
> > @b = (40,50,60);
> > 
> > $s = (@a,@b);
> > print "$s\n";
> > #versus
> > ($s) = (@a,@b);
> > print "$s\n";
> > 
> > 
> > In the first case the @a and @b are evaluated in scalar context. Even
> > though they are enclosed in braces.
> 
> Dang!
> 
> But your example helped -- this one makes sense to me, at least:
> 
> perl -e '@a=(1,2,3);@b=(4,5,6,7);@l{1,2}=(@a,@b);print "$l{1}\t$l{2}\n";'
> 
> Should I think of this as:  ($l{1}, $l{2}) = (@a,@b)
> ?
> 
> If so, then that makes a lot more sense to me.

Right. That's it. 
The fact that there is the same number of things in the braces on 
both sides of the equals might be a bit confusing at first, but it's 
irrelevant. Since in this case the equals provide a list context for 
the (@a,@b), the two arrays are flattened into one list. So 


($l{1}, $l{2}) = (@a,@b,@c);

or 

($l{1}, $l{2}, $l{4}) = (@a,@b);

would be just as OK. The commas are not matched, the elements of the 
two lists are. The list of specified elements of %l and the list of 
all elements of @a and @b.

Jenda
===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
        -- Terry Pratchett in Sourcery


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


Reply via email to