Tom Christiansen wrote:
> 
>     % man perlfunc
>     ...
>     When assigning to a list, if LIMIT is omitted, Perl supplies a
>     LIMIT one larger than the number of variables in the list, to
>     avoid unnecessary work.

As usual I picked a bad example. And I did read the perlfunc manpage,
but somehow both (a) forgot about split's 3rd argument and (b) missed it
on the rereading. This was example number 100+ on my list, so I was
feeling a little woozy. RTFM.
 
> This is documented behavior.  I don't understand the hubbub.

Yeah, oops. Sorry for wasting bandwidth. <sound of self-flogging>


Let me shift gears and instead ask whether anyone thinks this:

> >   $y = ($first, $second) = grep /$pat/, @data;

Returning "5" has any value? If you're going to do this, it seems like
you'd want the number that were really returned (since scalar grep
will give you the total number found anyways). 

If so, then generalizing split's behavior to return smaller lists when
they're requested might make things faster. In particular, grep could
potentially stop much sooner if you only wanted the first two matches,
and @data was 20,000 elements. If this was extended to user subs, Perl
could actually DWIM speed improvements if the sub was building a huge
list only to want the first few elements back.

The only potential problem I see is that "=()=" would always return 0
now, since it has no elements it's asking for. Hmm. Maybe "=()=" could
be special-cased to mean an infinitely hungry list, which is pretty 
much what it means right now.

Anyways, just an idea.

-Nate

P.S. Consider list() a dead horse for now. No additional flogging
required.

Reply via email to