Tom Christiansen wrote:
> 
> Ever consider then having
> 
>     ($a, $b, $c) = <FH>;
> or
>     @a[4,1,5] = <FH>;
> 
> only read three lines?  I mean, how many if any builtins would it
> make sense to make aware of this, and do something "different"?

Personally, I think this would be really cool; stuff like this is what I
was trying to poke at. Lots more power and flexibility. I could name
lots of builtins this potentially makes sense for:

   ($one, $two) = grep /pat/, @data;
   ($k1, $k2)   = keys %hash;  # leave index at $k3?
   @a[6,5,4]    = map { split ' ' } @line;
   ($last)      = reverse @array;            

And then there's splice, sort, and any and every user-defined sub too.
The only problem is when grep and map are used to change values on the
fly...this will have to be addressed. But actually, the behavior could
potentially be quite cool - maybe only the number requested back are
changed. Hmmm.

> Seems a bit rare and unimportant -- until one observes how this
> would also solve the problem of people being confused by this
> gobbling up their handle:
> 
>     my($line) = <FH>;

And a nice side effect too. As Peter says, the only problem is people
that are relying on this to get the actual last line...but I suspect
that's far fewer people than the ones would just want the first line and
used ()'s on my out of habit.

The more I think about it, this actually might make things more
consistent too. For example, currently these two aren't the same: 

   $count = @a = ($a, $b) = grep /pat/, @data;
   $count = ($a, $b) = @a = grep /pat/, @data;

But these two are:

   $count = ($a, $b) = grep /pat/, @data;
   $count = @a = grep /pat/, @data;

Which, actually, is a little weird when you really think about it. I
wouldn't feel bad about "breaking" (fixing?) this, though, since this:

   $count = grep /pat/, @data;
   $count = grep /pat/, @data;

Is probably how you should be getting the count anyways.

Well, as Damian suggests this should probably be RFC'ed. Since I brought
the whole mess up I'll do it, but I'd really appreciate if people could
send me any input they want to add. It'll likely take me 1-2 weeks,
though, since I have 4 other new ones to write and really have to update
my existing ones. I'll post it to -io when it's finished.

-Nate

Reply via email to