Title: RE: [Perl-unix-users] Index of array element

are the names unique? If so, a hash would be faster. Nevertheless, I'd do something like....

my $index;
my @names = qw(Bob Mary Fred Julio);
my $matchthis = "Fred";
for (my $i = 0; $i < scalar(@names); $i++)
{
        if ($names[$i] eq $matchthis)
        {
                $index = $i;
                last;
        }

}

print $index;



-----Original Message-----
From: Craig Sharp [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, December 03, 2003 10:00 AM
To: [EMAIL PROTECTED]
Subject: [Perl-unix-users] Index of array element


I have an array of names.  I need to find the corresponding index for a
particular name.  How can I do this?

Thanks,

Craig
_______________________________________________
Perl-Unix-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to