Tom Christiansen wrote:
>
> >Well, it only does this if it's not something like 'split', then!
>
> Yes, it does "do it" with split. split is defined to do what it
> does, how it does it. *This* is the kind of senseless harping that
> annoys me, Nathan.
Hmmmm. I'm apparently not making myself clear then.
Here is my suggestion: What if other functions were able to backtrace
context and determine how many arguments to return just like split can?
What split does is *cool*. That's my point. This would allow them to
possibly greatly optimize their return values (just like split).
For example, in Perl you have for a long time been able to do this:
($one, $two) = grep /$pat/, @data;
However, what currently happens is grep goes to completion, then
discards possibly huge amounts of data just to return the first two
matches. For example, if @data was 20,000 elements long, you could
potentially save a good chunk of time if you only had to return the
first and/or second match, rather than finding 1000 only to throw 998
away.
Imagine a new function of some kind that returns how many elements you
want back if in list context:
sub do_intensive_stuff {
if ( want eq 'LIST' ) {
$number_to_return = how_many_elements_to_return_builtin();
for ( $i = 0; $i < $number_to_return; $i++ ) {
# do something really computationally expensive
push @results, $this_loops_value;
}
return @results;
}
}
Then, if you called this in your program:
($one, $two) = do_intensive_stuff;
do_intensive_stuff would only have to go far enough to return two
values, possibly saving oodles of time and being much faster. This
behavior would be *optional*.
This is my point. Not that split's broken. But what if split's mechanism
could be extended outside of just split, as a general-purpose mechanism?
I'd be surprised if you were against this; I think you just
misunderstood my previous email.
-Nate
P.S. I just spent the past three hours reading through the 5.6 docs +
Camel-3, and I can't find a mechanism like this anywhere. So if it's
there, I apologize in advance, but I'm surely not aware of one. It looks
like something that could be put in caller(), but I didn't find any
evidence it was there currently.