W
Willem
Today I got bitten by a very strange bug/feature:
I wrote a function that returned a sorted list of things.
This function was used in several places, sometimes to use the things in
some way, and in one place just to check if it returned any things.
For example:
....
for my $s (get_sorted_things($foo)) {
do_something_with($s);
}
....
if (get_sorted_things($bar)) {
warn "There were things for $bar!\n";
}
....
sub get_sorted_things
{
my %unique = map { $_->Key => $_ } get_things();
return sort { $a->Property cmp $b->Property } values %unique;
}
And, because somebody decided that sort should always return undef
when called in scalar context, this does not work!
Why was it decided that sort returns undef in scalar context ?
IMO it is much more logical and consistent to have it return the
number of objects in the list that is to be sorted (it doesn't even
need to sort them for that).
SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
I wrote a function that returned a sorted list of things.
This function was used in several places, sometimes to use the things in
some way, and in one place just to check if it returned any things.
For example:
....
for my $s (get_sorted_things($foo)) {
do_something_with($s);
}
....
if (get_sorted_things($bar)) {
warn "There were things for $bar!\n";
}
....
sub get_sorted_things
{
my %unique = map { $_->Key => $_ } get_things();
return sort { $a->Property cmp $b->Property } values %unique;
}
And, because somebody decided that sort should always return undef
when called in scalar context, this does not work!
Why was it decided that sort returns undef in scalar context ?
IMO it is much more logical and consistent to have it return the
number of objects in the list that is to be sorted (it doesn't even
need to sort them for that).
SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT