bartrad has asked for the wisdom of the Perl Monks concerning the following question:
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; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Push array to hash
by BillKSmith (Monsignor) on Jun 24, 2020 at 16:07 UTC | |
by AnomalousMonk (Archbishop) on Jun 24, 2020 at 20:31 UTC | |
|
Re: Push array to hash
by haukex (Archbishop) on Jun 25, 2020 at 07:03 UTC | |
|
Re: Push array to hash
by AnomalousMonk (Archbishop) on Jun 24, 2020 at 20:56 UTC | |
|
Re: Push array to hash
by clueless newbie (Curate) on Jun 24, 2020 at 20:10 UTC | |
by haukex (Archbishop) on Jun 25, 2020 at 06:41 UTC | |
by Anonymous Monk on Jun 25, 2020 at 09:24 UTC | |
|
Re: Push array to hash
by perlfan (Parson) on Jun 24, 2020 at 21:11 UTC | |
|
Re: Push array to hash
by bartrad (Beadle) on Jun 25, 2020 at 10:54 UTC |