my @array_data = qw( 21 45 perl 28 monks);
foreach my $data (@array_data){
print $data,"\n";
}
Update:
However, if you want to iterate over the array, using the index of the array, Perl also does that for you very cleanly.
my @array_data = (21,45,'perl',28,'monks',' ','togo');
for my $num (0..$#array_data){
print $num,': ',$array_data[$num],"\n";
}
0: 21
1: 45
2: perl
3: 28
4: monks
5:
6: togo
Please, note that I used foreach and for inter-changeably.
And please don't forget that array index start from 0 and not 1, as used in your OP for loop.
Hope this helps
If you tell me, I'll forget.
If you show me, I'll remember.
if you involve me, I'll understand.
--- Author unknown to me
|