411 REFERENCE · Wikibooks
Perl Programming/Keywords/foreach
Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.
Perl for fork Keywords
The foreach keyword
foreach is the keyword used to start a foreach loop.
Syntax
foreach my $variable (@list) …;
Examples
The code
use 5.10.0;
%favorite = (joe => 'red', sam => 'blue', walter => 'black');
%list = %favorite;
say "%favorite = ";
foreach my $element (%favorite) {
say $element;
} returns the following: %favorite =
walter
black
joe
red
sam
blue
See also
Control flow
Perl for fork Keywords