for loop on an arrray in perl code example
Example 1: perl array loop
# syntax
foreach my $<element-name> (@<array-name>) {
# use $<element-name> in code
print $<element-name> . "\n";
}
# example
my @YourArray = ("a","bb","ccc");
foreach my $element (@YourArray) {
print $element . "\n";
}
Example 2: perl for loop
#!/usr/bin/perl
use warnings;
use strict;
my @c = (1..6);
for(my $i = 0; $i <= $#c; $i++){
print("$c[$i] \n");
}