Question: I am relatively new to Perl and I do not want to use the [List::Util](http://perldoc.perl.org/List/Util.html) `max` function to find the maximum value of a given array.

When I test the code below, it just returns the first value of the array, not the maximum.

```
sub max
{
    my @array = shift;
    my $cur = $array[0];
    foreach $i (@array)
    {
        if($i > $cur)
        {
            $cur = $i;
        }
        else
        {
            $cur = $cur;
        }
    }
    return $cur;
   }

```

Answer: 
Replace

```
my @array = shift;

```

with

```
my @array = @_;

```

`@_` is the array containing *all* function arguments. `shift` only grabs the first function argument and removes it from @\_. Change that code and it should work correctly!
Why don't you want to use something that works? 

One of the ways to solve problems like this is to debug your data structures. At each step you print the data you have to see if what you expect is actually in there. That can be as simple as:

```
 print "array is [@array]\n";

```

Or for complex data structures:

```
 use Data::Dumper;
 print Dumper( \@array );

```

In this case, you would have seen that `@array` has only one element, so there it must be the maximum.

If you want to see how list assignment and subroutine arguments work, check out [Learning Perl](http://oreilly.com/catalog/9780596520113).