
- Perl - Home
- Perl - Introduction
- Perl - Environment
- Perl - Syntax Overview
- Perl - Data Types
- Perl - Variables
- Perl - Scalars
- Perl - Arrays
- Perl - Hashes
- Perl - IF...ELSE
- Perl - Loops
- Perl - Operators
- Perl - Date & Time
- Perl - Subroutines
- Perl - References
- Perl - Formats
- Perl - File I/O
- Perl - Directories
- Perl - Error Handling
- Perl - Special Variables
- Perl - Coding Standard
- Perl - Regular Expressions
- Perl - Sending Email
- Perl - Socket Programming
- Perl - Object Oriented
- Perl - Database Access
- Perl - CGI Programming
- Perl - Packages & Modules
- Perl - Process Management
- Perl - Embedded Documentation
- Perl - Functions References
- Perl Useful Resources
- Perl - Questions and Answers
- Perl - Quick Guide
- Perl - Cheatsheet
- Perl - Useful Resources
- Perl - Discussion
Perl foreach Loop
The foreach loop iterates over a list value and sets the control variable (var) to be each element of the list in turn −
Syntax
The syntax of a foreach loop in Perl programming language is −
foreach var (list) { ... }
Flow Diagram

Example
#!/usr/local/bin/perl @list = (2, 20, 30, 40, 50); # foreach loop execution foreach $a (@list) { print "value of a: $a\n"; }
When the above code is executed, it produces the following result −
value of a: 2 value of a: 20 value of a: 30 value of a: 40 value of a: 50
perl_loops.htm
Advertisements