> > Does anyone help me about how I can > > find the maximum and minumum element > > of an array? > > my ( $min, $max ); > for ( @array ) { > $min = ( $min, $_ )[ $min >= $_ ]; > $max = ( $max, $_ )[ $max <= $_ ]; > } > > John > --
TIMTOWTDI showoff ;-) But you can simplify by using > instead of >=, similarly for <. Of course, you could also solve it like this: my @array = qw(93 96 34 12 65); ($max, $min)=("@array"=~/^([\d.]+)/, $1); "@array"=~/(?:^|[^\d.])([\d.]+)(?=[^\d.]|$)(?{$max<$1?$max=$1:{}})$/; "@array"=~/(?:^|[^\d.])([\d.]+)(?=[^\d.]|$)(?{$min>$1?$min=$1:{}})$/; print "Maximum = $max\n"; print "Minimum = $min\n"; Jonathan Paton __________________________________________________ Do You Yahoo!? Everything you'll ever need on one web page from News and Sport to Email and Music Charts http://uk.my.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]