Using array length in foreach statement
#!/usr/bin/perl -w
use strict;
my @questions = qw(Java Python Perl C);
my @punchlines = ("A","B","C",'D');
foreach (0..$#questions) {
print " $questions[$_] ";
sleep 2;
print $punchlines[$_], "\n\n";
sleep 1;
}
Related examples in the same category