foreach and array : Foreach Statement Perl

 

#!/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 "$strn";
}
print "Out of the loop--$str is $str.n";
print "Out of the loop--The array @numbers is now @numbers.n";

   
  

foreach Loop Hash Processing : Foreach Statement Perl

  


#!/usr/local/bin/perl
print " SORTED INDEXES OF THE HASH %ENV n";
foreach $key (sort (keys %ENV)){
   print "key = $key and retrieves: $ENV{$key}n";
}
print "n  SORTED VALUES OF THE HASH %ENV n";
foreach $value (sort (values %ENV)){
  print "value = $value}n";
}