Linux.com

The Perl way of iterating over an array

Posted by: Administrator on July 08, 2004 02:18 AM
The "native" way to do this is:

@users = (eric, billy, eddie, yngwie);
foreach (@users)
{
print "$_\n";
}

or
@users = (eric, billy, eddie, yngwie);
foreach my $user (@users)
{
print "$user\n";
}

or

@users = ('eric', 'billy', 'eddie', 'yngwie');
print "$_\n" foreach @users;

#

Return to SysAdmin to SysAdmin: Approaching Perl