Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Create an Array, loop over with foreach

  • @
use strict;
use warnings;

my @colors = ("Blue", "Yellow", "Brown", "White");
print "@colors\n";

foreach my $color (@colors) {
    print "$color\n";
}

Blue Yellow Brown White
Blue
Yellow
Brown
White

Perl for loop explained with examples