in reply to Re^3: nested <FILE> read returns undefined?
in thread nested <FILE> read returns undefined?
the important part here is the list context.
As usual, retrospect is 20/20, and now I see it. However, it's easy to see how one can be confused in the first place.
for my $line (<FILE>)
sure looks like scalar context, because $line isn't an array. This is further underscored by the fact that the loop will assign the next "line" to the variable. Because it feels like <FILE> is being read line-by-line, it's easy to see how for is treating <FILE> like a one-item array upon each iteration. Cap it all off with Duff's comment that perl 6 will "do the right thing" by... well, doing what I just described.
So, which is the right(tm) way? The @array context that it's currently doing (that you described)? Or the line-at-a-time way that I described, and that will be part of perl6?
I can see it both ways now, which is why I think the biggest problem is that this very thing isn't spelled out more explicitly in the perl book.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: nested <FILE> read returns undefined?
by tirwhan (Abbot) on Apr 01, 2006 at 08:44 UTC | |
by argv (Pilgrim) on Apr 01, 2006 at 18:56 UTC |