in reply to D'Orcish Maneuver
Dorkish indeed. I don't see how that makes any sense.
First, it gives tons of warnings. Second, it doesn't make sense to treat an error signal as a valid value.
$ perl -wE' sub expensive_call { $_[0] == -1 ? undef : $_[0] } say $_ // "[undef]" for sort { ( $c{$a} //= expensive_call($a) ) <=> ( $c{$b} //= expensive_call($b) ) } 0,1,-1,-1,0,2; ' Use of uninitialized value $c{"-1"} in numeric comparison (<=>) at -e +line 3. Use of uninitialized value $c{"-1"} in numeric comparison (<=>) at -e +line 3. Use of uninitialized value $c{"-1"} in numeric comparison (<=>) at -e +line 3. Use of uninitialized value $c{"-1"} in numeric comparison (<=>) at -e +line 3. Use of uninitialized value $c{"-1"} in numeric comparison (<=>) at -e +line 3. Use of uninitialized value $c{"-1"} in numeric comparison (<=>) at -e +line 3. Use of uninitialized value $c{"-1"} in numeric comparison (<=>) at -e +line 3. 0 -1 -1 0 1 2
It would make more sense to handle the error, perhaps by dying or by using a sensible default.
$ perl -wE' sub expensive_call { $_[0] == -1 ? undef : $_[0] } say $_ // "[undef]" for sort { ( $c{$a} ||= expensive_call($a) // -1 ) <=> ( $c{$b} ||= expensive_call($b) // -1 ) } 0,1,-1,-1,0,2; ' -1 -1 0 0 1 2
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: D'Orcish Maneuver
by JavaFan (Canon) on Apr 28, 2011 at 09:47 UTC | |
by ikegami (Patriarch) on May 04, 2011 at 19:10 UTC |