On Tue, Jul 24, 2001 at 11:36:13AM -0400, Clinton A . Pierce wrote:
> While tinkering with a problem at work (listed below) I was considering
> why perl couldn't have an in-place sort function.
Aside from the fact that this sort of thing [HA!]...
foreach my $key (sort keys %hash) {
...
}
gets inconvenient. (See also, Python).
> #perl noted that this could be done in XS, certainly. I thought
> maybe this was worthy of hacking into Perl itself as a use for void
> (or scalar) context sort().
I think I like that idea.
sort @list; # in place
my $num = sort @list; # in place, yet curiously pointless
my @foo = sort @list; # normal
I'm trying to think of common places where C<sort @inplace> might
accidentally be used in list context, such as the end of a block,
subroutine or perhaps module, and thus the sort unexpectedly not work,
but can't really come up with anything that isn't silly.
I'm also thinking about backwards compatibility. Changing its
behavior in void context shouldn't be a problem. Scalar context might
be, although any current use is just downright silly.
I'm also thinking if there's any functionality in Perl that is
analogous. ie. in one context it leaves its arguments alone, in
another it modifies them.
Hmmmm.
--
Michael G. Schwern <[EMAIL PROTECTED]> http://www.pobox.com/~schwern/
Perl6 Quality Assurance <[EMAIL PROTECTED]> Kwalitee Is Job One
"None of our men are "experts."... because no one ever considers
himself expert if he really knows his job."
-- From Henry Ford Sr., "My Life and Work," p. 86 (1922):