Title: RE: [Perl-unix-users] Index of array element
You have it as an array, but if unique, then why not
setup as hash and you would not have to do any searching, but would know right a
way with just a simple test vs searching the whole array each
time.
Wags ;)
-Original Message-
> I have an array of names. I need to find the corresponding
> index for a particular name. How can I do this?
If you need to do this often, or for a potentially large amount of names,
you may be better off starting with a hash of names instead.
--
Mark Thomas[EMAIL PROTEC
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 $mat
Title: RE: [Perl-unix-users] Index of array element
@array = ('a','b','c');
for($i=0;$i<=$#array;$i++){
print "index is $i\n" if $array[$i] eq 'b';
}
J
-Original Message-
From: Craig Sharp [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, December 03, 2003 10:00 AM
To: [EMAIL
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