The foreach loop allows you to do something to each value in an array.
A quick example is below:
A quick example is below:
@numbers=(1,7,3,8,9); foreach $number(@numbers){ #makes $number point to array value; $number++; #$number is incremented by 1 which is refle +cted inside the actual array; } #Now if we print out all the numbers they should reflect our changes #ie @numbers is now equal to (2,8,4,9,10); foreach(@numbers){ #notice here we don't specify a variable so Perl us +es its default: [perlman:perlvar|$_] print "$_,"; #we print the changed numbers separated by commas }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: foreach loops
by mrbbking (Hermit) on Dec 16, 2001 at 01:08 UTC | |
by tilly (Archbishop) on Dec 16, 2001 at 05:00 UTC | |
by blakem (Monsignor) on Dec 16, 2001 at 01:17 UTC | |
by barun (Novice) on Feb 05, 2005 at 13:23 UTC | |
Re: foreach loops
by Anonymous Monk on Jun 28, 2001 at 18:40 UTC | |
Re: foreach loops
by Anonymous Monk on Nov 06, 2001 at 08:08 UTC | |
Re: foreach loops
by Bilbo (Pilgrim) on May 27, 2002 at 13:51 UTC | |
by Hofmator (Curate) on May 27, 2002 at 14:02 UTC | |
by Bilbo (Pilgrim) on May 27, 2002 at 14:23 UTC | |
by bivouac (Beadle) on Dec 03, 2002 at 16:32 UTC | |
Re: foreach loops
by Mr. Muskrat (Canon) on Dec 22, 2004 at 06:30 UTC | |
Re: foreach loops
by jamgill (Acolyte) on Oct 08, 2003 at 19:15 UTC | |
Re: foreach loops
by zemote (Scribe) on Feb 20, 2003 at 15:07 UTC | |
RE: foreach loops
by Anonymous Monk on May 24, 2000 at 05:37 UTC | |
incorrect output
by Anonymous Monk on Feb 05, 2005 at 12:53 UTC | |
by merlyn (Sage) on Feb 05, 2005 at 13:02 UTC | |
by Anonymous Monk on Feb 18, 2005 at 17:43 UTC | |
Re: foreach loops
by @rocks (Scribe) on Oct 30, 2002 at 21:50 UTC |
Back to
Tutorials