7.3. loop over elements of list with foreach

  • list

  • foreach ITEM (LIST) {BLOCK}

  • my - in the foreach loop

Example 7-1. examples/arrays/list_colors.pl

#!/usr/bin/perl
use strict;
use warnings;

foreach my $color ("Blue", "Yellow", "Brown", "White") {
    print "$color\n";
}

Blue
Yellow
Brown
White


If you are interested in on-site trainings by the author, please contact me directly.

Online courses:

Would you like to get
updated when I publish
the next article?

Follow me:

Google Plus Twitter RSS feed