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!
You can write the function as:

```
#!/usr/bin/perl

use strict; use warnings;

print max(@ARGV);

sub max {
    my $max = shift;
    $max >= $_ or $max = $_ for @_;
    return $max;
}

```

However, it would be far more efficient to pass it a reference to the array and even more efficient to use `List::Util::max`.