in reply to Need to check my understanding of this code...

line 4 gets the first entry from the list. It does the same as my $max_so_far = shift. And $max_so_far is the last statement and returned to the calling sub. So it is like return $max_so_far;
Boris
  • Comment on Re: Need to check my understanding of this code...

Replies are listed 'Best First'.
Re^2: Need to check my understanding of this code...
by dorward (Curate) on Sep 04, 2005 at 19:10 UTC

    Not quite. Shift removes the first entry from the list, a simple assignment doesn't (although since that list is never used again, in this context it makes no difference - except that the assignment is slightly faster). Compare:

    #!/usr/bin/perl use strict; use warnings; my @list = qw/a b c/; my ($x) = @list; print "X: $x, List: @list\n"; my $y = shift @list; print "Y: $y, List: @list\n";

    The output being:

    X: a, List: a b c
    Y: a, List: b c
    
      ???, I think one of us misread the question. I talk about the difference from my $x = shift; and my ($x) = shift @_; sure, there is a difference, but not in the context of the question.
      Boris

        Whoops. I've never seen anybody shift into an list context before. I must have had a bit of a blind spot there.