< Perl Programming < Keywords
![](../../../I/Crystal_Clear_action_apply.png.webp)
The code
The foreach keyword
foreach is the keyword used to start a foreach loop.
Syntax
foreach my $variable (@list) …;
Examples
![](../../../I/Crystal_Clear_action_apply.png.webp)
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
This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.