--On Samstag, 22. September 2001 01:09 +0200 Andrea Holstein 
<[EMAIL PROTECTED]> wrote:

> Birgit Kellner wrote:
>>
>> my %hash = ('firstkey' => 'firstvalue',
>>         'secondkey' => 'secondvalue',
>>         'thirdkey' => 'thirdvalue');
>> my @array = ('secondkey', 'other element', 'still other element',
>> 'firstkey');
>> my @index_array;
>> foreach my $element (@array) {
>>         # QUESTION: here I'd like to have some code that returns the
>>         index number of $element, which I'd store in $index
>>         if ($hash{$element}) {
>>                 push (@index_array, $index);
>>                 }
>>         }
>>
>> Any suggestions would be greatly appreciated,
>
> Simple solution is
> ...
> my $index = 0;
> foreach my $element (@array) {
>       if (...) {
>               ...
>       }
>       $index++;
> }
>
Thanks, but I don't understand how this is supposed to achieve what I want. 
As I understand it, this code simply increments the value of $index every 
time the condition evaluates true. In my case, the condition would be:
if ($hash${element}) {
        ...
}
So I'd increment the value of $index each time there's a hash value for an 
array element. But $index would not be the index number of the array 
alement in question.

Birgit Kellner





-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to