FOREACH loops
homencsa resources partnershipsoutreachsoftware_tech
alliance searchinside ncsa adv_computingsciencedivisions
left up right comment

FOREACH loops

The FOREACH construct takes advantage of perl's builtin list features by easily iterating over an entire array. The syntax is
 
	foreach SCALAR ( LIST ) { 
		STATEMENTS; 
	} 
Each time through the loop, SCALAR is assigned the next element in the LIST, and the STATEMENTS are executed. Consider this version of join:
 
	foreach $instrument ("violin","viola","cello","bass") { 
		print($instrument," is lighter than a \n"); 
	} 
	print("harp\n"); 

left up right comment



NCSA
The National Center for Supercomputing Applications

University of Illinois at Urbana-Champaign

johnsonb@ncsa.uiuc.edu

Last modified: June 19, 1997



Retrieved by Memoweb from http://www.ncsa.uiuc.edu/General/Training/PerlIntro/foreach.html at 08/02/99