Perl Tutorials -Part 42- Looping over an array

Posted on June 2, 2010. Filed under: Perl Tutorials |


#perl example of looping there array
@names = ('Amina', 'Bhimsen', 'Charles', 'Damien');

for ($i = 0; $i < @names; $i++)
{
         print "Name number $i is $names[$i]\n";
}

Output:

1
2
3
4
Name number 0 is Amina
Name number 1 is Bhimsen
Name number 2 is Charles
Name number 3 is Damien
Advertisements

Make a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Liked it here?
Why not try sites on the blogroll...

%d bloggers like this: