perlquestion
bartrad
<p>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?</p>
<code>
$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],
</code>
<p>The first structure appears just fine, but subsequent pushes only show as "${$VAR1}->[0]" - not sure why?</p>
<code>
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, "operationstate" => $3, "adminstate" => $2 );
}
}
if ( $line =~ m/somemoreregex/ ) {
my %port_detail = ( "port" => $1, "adminstate" => $2, "operationstate" => $4, "ismaster" => $3 );
push @{ $lag_detail{"ports"} }, \%port_detail;
}
}
</code>