in reply to Re: Notation of sort function
in thread Notation of sort function
Alphaphi: I dont see redundancy, I think the syntax is flexible to permit also different use cases.
> There are cases where one might want to apply different conditions on the operands..
mmh.. yes this can also be true but I suppose just as a trigger inside comparison: which apple is heavier but golden one count more
use strict; use warnings; use Data::Dump; my %apples = ( one => { weight => 10, golden=> 0}, two => { weight => 20, golden=> 0}, three => { weight => 5 , golden=> 1}, ); my @sorted = sort{ ( $apples{$b}->{golden} ? $apples{$b}->{weight} * 10 : $apples{$b}->{weight} ) <=> ( $apples{$a}->{golden} ? $apples{$a}->{weight} * 10 : $apples{$a}->{weight} ) }keys %apples; dd @sorted; __END__ ("three", "two", "one")
> ..or where one of the operands isn't $a or $b at all
I dont think this can be logic. Also in sort of misunderstanding of sort you can find that sort is optimized, so not every pair is checked so if you will sort apple against pear I wonder which use case can be.
Courious to know otherwise :)
L*
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Notation of sort function
by hippo (Archbishop) on Oct 28, 2023 at 12:43 UTC | |
|
Re^3: Notation of sort function
by Alphaphi (Acolyte) on Oct 27, 2023 at 14:05 UTC | |
by tybalt89 (Monsignor) on Oct 27, 2023 at 18:56 UTC | |
by kcott (Archbishop) on Oct 27, 2023 at 16:03 UTC | |
by ikegami (Patriarch) on Oct 27, 2023 at 19:11 UTC |