Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
my %fpc = ( R0 => { fpc1 => 5, fpc2 => 4, }, R2 => { fpc1 => 3, fpc2 => 2, }, R3 => { fpc1 => 1, fpc2 => 0, }, ); my %pic = ( R0 => { pic1 => 5, pic2 => 4, }, R2 => { pic1 => 3, pic2 => 2, }, R3 => { pic1 => 1, pic2 => 0, }, ); @router = ( "R0", "R2", "R3" ); for my $rh (@routers) { my $r = shift(@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; } } }
Output is
value of r is R0
request chassis pic offline fpc-slot 5 pic-slot 4
request chassis pic offline fpc-slot 4 pic-slot 4
I thought it will take first value of $pic{R0}, which is 5 but it is taking $pic{R0} second value. Also, is there a way to increment the second "for" loop also. In the second output, "request chassis pic offline fpc-slot 4 pic-slot 4", it is taking the correct values for fpc, but pic it is still retaining the old value 4. Is there a way to solve it?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: NEXT statement in for loop
by Corion (Patriarch) on Jun 05, 2016 at 16:26 UTC | |
by Anonymous Monk on Jun 05, 2016 at 16:49 UTC | |
by Corion (Patriarch) on Jun 05, 2016 at 17:30 UTC | |
by poj (Abbot) on Jun 05, 2016 at 17:55 UTC | |
|
Re: NEXT statement in for loop
by Laurent_R (Canon) on Jun 05, 2016 at 19:01 UTC | |
|
Re: NEXT statement in for loop
by Athanasius (Archbishop) on Jun 06, 2016 at 04:26 UTC | |
|
Re: NEXT statement in for loop
by Anonymous Monk on Jun 05, 2016 at 17:57 UTC | |
by Anonymous Monk on Jun 06, 2016 at 05:53 UTC | |
by Athanasius (Archbishop) on Jun 06, 2016 at 06:07 UTC | |
by Anonymous Monk on Jun 06, 2016 at 09:07 UTC |