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

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

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



Jun 13, 2000, 3:49 PM

Post #1 of 2 (828 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?


Jun 13, 2000, 4:10 PM

Post #2 of 2 (828 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";

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