Linux.com

Re:The Perl way of iterating over an array

Posted by: Administrator on July 08, 2004 02:21 AM
With some formatting this time:

The "native" way to do this is:
<TT>@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;</TT>

#

Return to SysAdmin to SysAdmin: Approaching Perl