Re: evaluate for max and min value in array

2009-07-22 Thread Chas. Owens
On Wed, Jul 22, 2009 at 12:11, Bryan R Harris wrote: snip > If your arrays could be very large, it's a waste of cycles to sort the list > then throw most of that effort away.  You could do: snip Due to the fact that sort is written in C, it can be faster to sort than to loop over the array in Perl

Re: evaluate for max and min value in array

2009-07-22 Thread Chas. Owens
On Wed, Jul 22, 2009 at 03:30, sheela b wrote: > Hi Jenn, > > You can fing max and min value as, > > my @ar = (1,2,3,4,58,9,2,1); > my $max = (sort { $b <=> $a } @ar)[0]; > my $min = (sort { $a <=> $b } @ar)[0]; snip This is only efficient up to about 250 values in @ar, if @ar is going to have mor

Re: evaluate for max and min value in array

2009-07-22 Thread Bryan R Harris
> You can fing max and min value as, > > my @ar = (1,2,3,4,58,9,2,1); > my $max = (sort { $b <=> $a } @ar)[0]; > my $min = (sort { $a <=> $b } @ar)[0]; If your arrays could be very large, it's a waste of cycles to sort the list then throw most of that effort away. You could do: **

Re: evaluate for max and min value in array

2009-07-22 Thread Jenn G.
thanks all the suggestions. On Wed, Jul 22, 2009 at 4:32 PM, Shawn H. Corey wrote: > Jenn G. wrote: >> >> Hello, >> >> How to lookup the max and min value in an array? >> Just like SQL's max() and min() functions. >> >> Thanks. >> > > use List::Util qw/min max/; > > See `perldoc List::Util` for de

Re: evaluate for max and min value in array

2009-07-22 Thread Shawn H. Corey
Jenn G. wrote: Hello, How to lookup the max and min value in an array? Just like SQL's max() and min() functions. Thanks. use List::Util qw/min max/; See `perldoc List::Util` for details. -- Just my 0.0002 million dollars worth, Shawn Programming is as much about organization and c

Re: evaluate for max and min value in array

2009-07-22 Thread sheela b
Hi Jenn, You can fing max and min value as, my @ar = (1,2,3,4,58,9,2,1); my $max = (sort { $b <=> $a } @ar)[0]; my $min = (sort { $a <=> $b } @ar)[0]; Regards Sheela On Wed, Jul 22, 2009 at 12:48 PM, Jenn G. wrote: > Hello, > > How to lookup the max and min value in an array? > Just like SQL's

evaluate for max and min value in array

2009-07-22 Thread Jenn G.
Hello, How to lookup the max and min value in an array? Just like SQL's max() and min() functions. Thanks. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/