msgbartop
Just another WordPress site
msgbarbottom

12 Nov 08 Perl Loop Basics

For loop

The below will print “Hello!” 10 times:

  for ($i = 0; $i < 10 ; $i++){   print "Hello!n"; }
  Output: Hello!

Foreach loop

For iterating through an array it can be handy to use a foreach loop. In the example below the foreach loop will access each variables in the array and allow you to use it as $i:

  @array = ('one','two','three');
  foreach $i (@array) {   print "$i, "; }
  Output: one, two, three,