in reply to NEXT statement in for loop

As the title of this thread is “NEXT statement in for loop,” it may be as well to look at the three nested for loops in the OP and examine their structure. Adopting Laurent_R’s simplification, we get:

for my $r (@router) { print "value of r is $r\n"; OUTER: for my $f (values %{ $fpc{$r} }) { INNER: for my $p (values %{ $pic{$r} }) { print "request chassis pic offline fpc-slot $f pic-slot $p +\n"; next OUTER; } } }

The effect of the next statement is to terminate the INNER loop after its first iteration; so the code can be written equivalently with just two loops:

for my $r (@router) { print "value of r is $r\n"; OUTER: for my $f (values %{ $fpc{$r} }) { my $p = (values %{ $pic{$r} })[0]; print "request chassis pic offline fpc-slot $f pic-slot $p\n"; } }

See next and Loop Control.

As others have noted, hashes are unordered, so the list returned by values %{ $fpc{$r} } will vary across successive runs of the script. If an ordered hash is required, has various options; for example, Hash::Ordered — and note the “SEE ALSO” section in that module’s documentation.

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,