in reply to Multiple loop variable in foreach statement

This should match each pair for you:

for my $key_raw (@keys_raw) { for my $key_ref (@keys_ref) { .... } }

Update:

Hm... this is just in general. In your case, both arrays are sorted, so you should use something that has a better performance. You should always remember the last used index for the inner loop. For each iteration of the outter loop, the inner loop should start from there.

Replies are listed 'Best First'.
Re^2: Multiple loop variable in foreach statement
by tc1364 (Beadle) on Oct 12, 2004 at 16:46 UTC
    Well, I tried this already and what appears to happen is that the for loops act independently and not as one because the below code should only report one time (I changed one character in one of the files that made up the hash tables). $val_raw = $raw58{$key_raw}; $val_ref = $ref58{$key_ref}; if ($key_raw eq $key_ref && $val_raw eq $val_ref) { next; } else { print "$key_raw $val_raw $key_ref $val_ref\n"; }