Rod Adams <rod@rodadams.net> wrote: > > $fh -> > > $fh» (and $fh>>) > > $fh> > ++$fh That kind of breaks the metaphor, unfortunately. I've been thinking more on this, and I may have a better reason for not liking this proposal. I'm going to pull a Larry and think out loud for a minute here. Note that I speak authoritatively here, as if I'm the language designer; this is just to avoid putting "I would..." everywhere. I think my problem with the proposed syntax is metaphor shear. This example code: for (@$input) { ... } works whether $input is a filehandle or an arrayref. So a user may decide to do this: say $input[42]; which I suspect won't work. Even if it does, this code: for(@$input) { ... } say $input[0]; probably wouldn't. The problem is that filehandles are iterators--which aren't arrays. An iterator has different characteristics from an array--i.e. it's accessed more or less sequentially and access is destructive. Treating it like an array is wrong. On the other hand, what if a filehandle *is* an array? What if you can access it randomly and non-destructively? If it is, we already have a name for "fetch". In Perl 5, we call a destructive fetch from the front of an array "shift". So: $fh=open "foo.txt"; say $fh.shift; for $fh.shift($fh.elems) { ... } Of course, $fh.shift($fh.elems) deserves a shortcut. Perhaps $fh.shiftall(), which creates a lazy copy and "empties" the filehandle. But .shift looks a bit awkward. I suggest a name change for .shift and .unshift, so that we have: push, pop pull, put So now we have: my $fh=open "foo.txt"; say $fh.pull; for $fh.pullall { ... } And what about iterators in general? Well, if we can do it to filehandles, why not all iterators? An iterator is simply a lazy array copy that isn't accessed randomly; instead, the .pull and .pullall methods are used for access. .push can be used to append to it, .put can be used to put an item back on the front. .pop is a bit useless, but that's not really a problem. That doesn't mean you *can't* randomly access an iterator--after all, it's just a lazy array copy. But it might be slower, or otherwise unwise. At the point where a filehandle is just an array and you can use most normal array operations on it, I can see not having a special operator for reading a file. Without that, though, I think the metaphor shear of @$fh is too harsh, and the duplication between .fetch and .[shift|pull] isn't necessary. -- Brent 'Dax' Royal-Gordon <brent@brentdax.com> Perl and Parrot hacker "I might be an idiot, but not a stupid one." --c.l.p.misc (name omitted to protect the foolish)