[Perl-unix-users] Index of array element

2003-12-03 Thread Craig Sharp
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


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

2003-12-03 Thread Jason Vincent
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 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





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

2003-12-03 Thread Peter Eisengrein
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





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

2003-12-03 Thread Thomas, Mark - BLS CTR
> 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 PROTECTED]
Internet Systems Architect User Technology Associates, Inc.

$_=q;KvtuyboopuifeyQQfeemyibdlfee;; y.e.s. ;y+B-x+A-w+s; ;y;y; ;;print;;
 

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


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

2003-12-03 Thread Wagner, David --- Senior Programmer Analyst --- WGO
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-From: 
  [EMAIL PROTECTED] 
  [mailto:[EMAIL PROTECTED]On Behalf Of 
  Jason VincentSent: Wednesday, December 03, 2003 
  10:50To: Craig Sharp; 
  [EMAIL PROTECTED]Subject: 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 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 


**
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.