Perl: Foreach loop

This Comment will be submitted for moderation and will not be accessible to other users until it has been approved.


Perl foreach iterates through each element in the array or the list as follows: @persons = ("hari", "david", "mika"); foreach $person (@persons){ print "A Person in persons array is $person \n"; } This would print: A Person in persons array is hari A Person in persons array is david A Person in persons array is mika





Post Comment

  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <c>, <cpp>, <drupal5>, <drupal6>, <java>, <javascript>, <php>, <python>, <ruby>. Beside the tag style "<foo>" it is also possible to use "[foo]". PHP source code can also be enclosed in <?php ... ?> or <% ... %>.