I may be looking at this wrong, but it seems as though the preposed solution
would work. Since the incrementing is done outside the brackets of the if
statement, the index is incremented for each element regardless of the
outcome of the if statement.
Joyce
----- Original Message -----
From: "birgit kellner" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, September 21, 2001 9:27 PM
Subject: Re: store index numbers of all array1 elements in array2
whichequalkeys in a hash
> --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]
>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]