edieguez has asked for the wisdom of the Perl Monks concerning the following question:
sub find { my($var, @array); $var =$_[0]; @array=@_[1..$#_];; my $index = 0; ++$index until $array[$index] == $var or $index > $#array; #print "@array\n"; #print "$array[$index]\n"; return $index; } $result = &find (‘Q', @fsg); print "$result\n $fsg[$result]\n”; # returns index for the first non- +integer regardless of what that item is $result = &find (‘2', @fsg); print "$result\n $fsg[$result]\n”; # returns correct index $result = &find (‘102', @fsg); print "$result\n $fsg[$result]\n”; # returns the length as the array a +s the index - which is the value I check to see if a match occurred o +r not.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Searching mixed array?
by Corion (Patriarch) on Apr 26, 2011 at 21:02 UTC | |
|
Re: Searching mixed array?
by kennethk (Abbot) on Apr 26, 2011 at 20:58 UTC | |
|
Re: Searching mixed array?
by toolic (Bishop) on Apr 26, 2011 at 21:07 UTC | |
by edieguez (Initiate) on Apr 27, 2011 at 02:27 UTC | |
by kennethk (Abbot) on Apr 27, 2011 at 13:18 UTC |