title: Why does my Perl max() function always return the first element of the array?
body: <p>I am relatively new to Perl and I do not want to use the <a href="http://perldoc.perl.org/List/Util.html" rel="nofollow noreferrer">List::Util</a> <code>max</code> function to find the maximum value of a given array.</p>
  
  <p>When I test the code below, it just returns the first value of the array, not the maximum.</p>
  
  <pre><code>sub max
  {
      my @array = shift;
      my $cur = $array[0];
      foreach $i (@array)
      {
          if($i &gt; $cur)
          {
              $cur = $i;
          }
          else
          {
              $cur = $cur;
          }
      }
      return $cur;
     }
  </code></pre>