Hi, I've got a strange problem I can't get my head round. I'm pushing a hash and the first one appears in OK, but subsequent ones appear wrong?
$VAR1 = \[ { 'desc' => 'xxx', 'ports' => [ { 'adminstate' => 'up', 'operationstate' => 'down', 'port' => '80', 'ismaster' => 'active' }, { 'adminstate' => 'up', 'operationstate' => 'down', 'port' => '81', 'ismaster' => 'active' }, { 'adminstate' => 'up', 'operationstate' => 'down', 'port' => '82', 'ismaster' => 'active' } ], 'adminstate' => 'up', 'lagid' => '45', 'operationstate' => 'down' }, ${$VAR1}->[0], ${$VAR1}->[0], ${$VAR1}->[0], ${$VAR1}->[0],
The first structure appears just fine, but subsequent pushes only show as "${$VAR1}->[0]" - not sure why?
foreach my $line ( split( /\n/, $c ) ) { if ( $line =~ m/someregex/ ) { if ( exists( $lag_detail{"ports"} ) ) { push( @{ $self->{"lags"} }, \%lag_detail ); } %lag_detail = ( "lagid" => $lag, "lagdesc" => $4, "operationst +ate" => $3, "adminstate" => $2 ); } } if ( $line =~ m/somemoreregex/ ) { my %port_detail = ( "port" => $1, "adminstate" => $2, "operationst +ate" => $4, "ismaster" => $3 ); push @{ $lag_detail{"ports"} }, \%port_detail; } }
In reply to Push array to hash by bartrad
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |