Mega Code Archive

 
Categories / Perl / Statement
 

Foreach and array

#!/usr/bin/perl $str="hello"; @numbers = (1, 3, 5, 7, 9); print "\$str is initially $str.\n"; print "\@numbers is initially @numbers.\n"; foreach $str (@numbers ){      $str+=5;      print "$str\n"; } print "Out of the loop--\$str is $str.\n"; print "Out of the loop--The array \@numbers is now @numbers.\n";