Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: NEXT statement in for loop

by Anonymous Monk
on Jun 05, 2016 at 17:57 UTC ( [id://1164940]=note: print w/replies, xml ) Need Help??


in reply to NEXT statement in for loop

I thought it will take first value of $pic{R0}, which is 5 but it is taking $pic{R0} second value.

To emphasize something that Corion pointed out in his answer: Hashes are unordered. There is no "first" or "second" value. If you need things in order, you should probably put them in an array, not a hash.

my %pic = ( R0 => [ 5, 4 ], R2 => [ 3, 2 ] );

Replies are listed 'Best First'.
Re^2: NEXT statement in for loop
by Anonymous Monk on Jun 06, 2016 at 05:53 UTC

    But, you can't define array in hash, right ?. I don't think this will work

    my %pic = ( R0 => [ 5, 4 ], R2 => [ 3, 2 ] );

        Yes, tried and worked

        Pasting the final code

        my @r = qw/h1 h2/ ; my $rh = JT->new( host => $r[0] ); my $rh = JT->new( host => $r[1] ); my $output; my $key; my $value; my @routers =($r[0], $r[1]); my @router = ( "R0", "R1", "R2" ); my %fpc = ( R0 => [5,4], R1 => [3,2], R2 => [1,0], ); my %pic = ( R0 => [5,4], R1 => [3,2], R2 => [1,0], ); ); @router = ( "R0", "R1", "R2" ); for my $rh (@routers) { my $r = shift(@router); print "value of r is $r\n"; my $count = 0; for my $f (@{ $fpc{$r} }) { # for my $p (@{ $pic{$r} }) { my $p = (@{ $pic{$r} })[$count]; print "request chassis pic offline fpc-slot $f pic-slot $p +\n"; $count++; #} } }

        . Thanks all

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1164940]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2024-03-28 08:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found