Using foreach to iterate over an array. : Foreach « Statement « Perl

Home
Perl
1.Array
2.CGI
3.Class
4.Data Type
5.Database
6.File
7.GUI
8.Hash
9.Language Basics
10.Network
11.Regular Expression
12.Report
13.Statement
14.String
15.Subroutine
16.System Functions
17.Win32
18.XML
Perl » Statement » Foreach 
Using foreach to iterate over an array.
 

@array = .. 10 );           # create array containing 1-10

foreach $number @array ) {    for each element in @array
   $number **= 2;               # square the value
}

print "@array\n";               

   
  
Related examples in the same category
1.foreach ( 1 .. 10 ) : loops 10 times, not requiring a control variable
2.Standard foreach structure. Prints the letters A-G
3.Duplicate of the foreach structure with for structure
4.Duplicate the for structure with the foreach keyword
5.Standard foreach structure, printing the values in a list
6.$_ takes the place of the control variable
7.Using foreach loops with hashes.
8.Using block labels with next in nested looping structures.
9.The foreach statement lets you iterate for each element in a list or array:
10.Each time through the loop, foreach places the next element of the list into the scalar variable.
11.Example of foreach from a min to a max.
12.Use foreach to loop through hash with keys function
13.foreach statement with number range
14.Using foreach to loop through an array without using the default value
15.Using foreach to loop through array variable
16.Declare variable in foreach statement
17.Using variable defined outside in foreach loop
18.Using predefined variable $_ in foreach loop
19.Mix $_ and foreach statement
20.Using array length in foreach statement
21.For each loop with array
22.For each loop with array and $_
23.The foreach statement iterates through list values, assigning a variable the value of each element in turn.
24.foreach statement.
25.Choosing an Iterator
26.If you declare your iterator outside the loop, any value it had then will be restored afterwards.
27.The foreach Loop
28.foreach and array
29.The foreach modifier evaluates once for each element, with $_ aliased to each element
30.foreach Loop Array Processing
31.foreach Loop Hash Processing
32.foreach Loop Hash Processing in a CGI Program
33.foreach (1 .. 10) range
34.Using foreach statement with print
35.Using foreach statement with hash
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.