next up previous
Next: Some useful Perl Up: Further Perl Programming Previous: The while/until statement

The foreach statement

The foreach statement iterates through items in a list: The statement has the following format:

foreach $i (@some_list)
  {  # $i takes on each list item value in turn
     statement(s);
  }

For example:

@a = (1, 2, 3, 4, 5);
foreach $i (reverse @a)
  { # reverse is a functiion that flips the list order
    print $i;
  }



Dave Marshall
9/28/2001