On Wed, Jul 22, 2009 at 03:30, sheela b<sheela.b.2...@gmail.com> 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 more values than that you should use the min and max functions from [List::Util][0] (note List::Util has been part of core Perl since version 5.8 and is available on CPAN for earlier versions): #!/usr/bin/perl use strict; use warnings; use List::Util qw/max min maxstr minstr/; my @num = (1,2,3,4,58,9,2,1); my @str = qw/a f d s e z s f t/; my $max = max @num; my $min = min @num; my $maxstr = maxstr @str; my $minstr = minstr @str; print "max $max min $min maxstr $maxstr minstr $minstr\n"; [0] : http://perldoc.perl.org/List/Util.html -- Chas. Owens wonkden.net The most important skill a programmer can have is the ability to read. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/