Mega Code Archive

 
Categories / Perl / Statement
 

Each time through the loop, foreach places the next element of the list into the scalar variable

#!/usr/bin/perl -w @languages = ("A","C","D","B","A"); foreach $lang (@languages) {     if ($lang eq "Perl") {         print "Perl is $lang.\n";     } else {         print "$lang ideas.\n";     } }