> Bryan R Harris wrote:
>>
>> John W. Krahn wrote:
>>>
>>> Bryan R Harris wrote:
>>>>
>>>>> Jenda Krynicky wrote:
>>>>>
>>>>> Context. The <FILEHANDLE> returns a single line in scalar context and
>>>>> a list of all lines in a list context. And there is no such thing as
>>>>> a two-item-list context.
>>>>>
>>>>> So in the first case the assignment to @l2r{"a","b"} provides a list
>>>>> context so the very first <FILE> reads all the lines left in FILE,
>>>>> the second and third return an empty list. The first two lists are
>>>>> concatenated together and the first two items of the resulting list
>>>>> are assigned to $l2r{"a"} and $l2r{"b"}. And the rest of the list is
>>>>> forgotten. You'd have to do something like
>>>>>
>>>>> @l2r{"a","b"} = (scalar(<FILE>), scalar(<FILE>));
>>>>> or
>>>>> @l2r{"a","b"} = (<FILE>.'', <FILE>.'');
>>>>>
>>>>> to ensure that the <FILE> is evaluated in scalar context.
>>>>
>>>> Which part is forcing the list context? The fact that the <FILE> is inside
>>>> parenthesis () or the @l2r{...} part?
>>>
>>> The left hand side of the assignment determines context so the @l2r{...}
>>> part.
>>
>> That strikes me as odd... When perl goes to populate @l2r{"a","b"}, it
>> seems to me that it would go through this process:
>>
>> - I have a slice here, so I'll loop over the slice elements
>> - The first is "a", so I'll pull a scalar off the list and assign it to
>> $l2r{"a"}
>> - The second is "b", so I'll pull another scalar off the list and assign it
>> to $l2r{"b"}
>> - Remaining scalars in the list are discarded
>
> Correct, except for the loop part.
>
>> Why would $l2r{"a"} here be considered list context?
>
> It isn't, unless it's written as ( $l2r{"a"} ), then it's a list with
> one element.
So I still don't understand what about @l2r{"a","b"} makes it evaluate the
first (<FILE>... in list context instead of scalar context.
>> What am I missing?
>
> Hard to say? :-)
Indeed.
Maybe this one's just too complex for my little brain.
- B
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/