in reply to Ternary vs. Sort vs. Max
Hello QM,
Another — possibly heretical? — option is to make max an inline function using a module such as macro:
#! perl use strict; use warnings; use macro max => sub { $_[0] > $_[1] ? $_[0] : $_[1]; }; my $x = $ARGV[0]; my $y = $ARGV[1]; my $m = max($x, $y); print "max is $m\n";
Output:
0:05 >perl 1334_Med.pl 17 12 max is 17 0:05 >perl -MO=Deparse 1334_Med.pl Compiling 1334_Med.pl by macro::compiler/0.06 ... sub Digest::base::new; sub Digest::base::clone; sub Digest::base::add; sub Digest::base::digest; use macro ('max', sub { use warnings; use strict; $_[0] > $_[1] ? $_[0] : $_[1]; } ); use warnings; use strict; my $x = $ARGV[0]; my $y = $ARGV[1]; my $m = $x > $y ? $x : $y; print "max is $m\n"; 1334_Med.pl syntax OK 0:05 >
Hope that helps,
Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Ternary vs. Sort vs. Max
by QM (Parson) on Aug 10, 2015 at 15:55 UTC | |
by Athanasius (Archbishop) on Aug 11, 2015 at 09:42 UTC | |
by QM (Parson) on Aug 11, 2015 at 14:41 UTC |
In Section
Meditations