CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Back calculate location in an array

 



jbs
Deleted

Jun 13, 2000, 3:49 PM

Post #1 of 2 (355 views)
Back calculate location in an array Can't Post

I have a little prob... I have an array called @num

@num=qw(one two three four five);
foreach $tmp (@num){
if($tmp eq "four")
#how do I find the location of four in @num

}

That is my problem.. I need to suck in data and when it matches I need it to find the location of the match in another array.. Am I approaching this in the correct manner?


dws
Deleted

Jun 13, 2000, 4:10 PM

Post #2 of 2 (355 views)
Re: Back calculate location in an array [In reply to] Can't Post

@num=qw(one two three four five);
$index = 0;
foreach $tmp (@num) {
last if $temp eq "four";
++$index;
}

if ( $index < @num ) {
# @num[$index] is the one you found
}

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives