Question: what is error in this code? 
could any give code for peak finding in an 1-d array in perl code?
I tried but i could complete if some one help me out.`

```
@a=(5.7,5.3,8.2,16.5,34.2,58.8,5.9,8,5,27.8);
@a=\$ptr;
$i;
$f=1;
$l=10;
$num=@a;
print"\nthe num of elements in array:$num";
$s=0;
$s=$s+$_ for @a;
print"\nthe sum of all elements in array:$s";
$mean=$s/$num;
print"\n the mean is :$mean";
$mid=($f+$l)/2;
print"\nthe mid point:$mid";
print"\nthe middle element :$a[5]";
unless($a[$i]==$a[5])
{if($a[$i]>$a[5])
for ($i=$a[5];$a[$i]<$a[5];$i--);
{
$ptr=$a[$i-1];
$ptr->$max;
print"$max";
}
}`

```

Answer: 
The cleanest way to find the max is to use the core [List::Util](http://perldoc.perl.org/List/Util.html) module.

```
use List::Util qw(max);

my $max = max @arr;

```
A quick way to do this is to use `sort`. But be sure to use a numeric comparator because sort sorts alphanumeric by default:

```
my @b = sort {$b <=> $a} @a;
print "$b[0]";

```

**UPDATE**

Or you can use `map` from `List::Util` - thanks @squiguy.

```
use List::Util qw(max);
my $peak = max(@a);

```

It's true that `sort` should be slower than `max` since the `max` algorithm is O(n) and sort is O(n \* log(n)). If @a is small enough then it doesn't matter. 

But, `max` has another benefit in that it is more indicative of what you are trying to do and, thus, more readable. `map` comes from `List::Util` which didn't become part of the Perl core until version `5.8.0`