Iterate over blessing objects in Perl

I am working on some code to query the F5 load balancer using the BigIP :: iControl module.

Right now, I get the following output when I execute a Dumper for a variable that I get from a specific function.

I have a lot of problems with iterating this object.

How can I keep repeating this and taking out only monitor_status for each member?

$VAR1 = [ bless( [ bless( { 'monitor_status' => 'MONITOR_STATUS_UP', 'member' => bless( { 'address' => '127.0.0.0.1', 'port' => '8085' }, 'Common::IPPortDefinition' ) }, 'LocalLB::PoolMember::MemberMonitorStatus' ), bless( { 'monitor_status' => 'MONITOR_STATUS_UP', 'member' => bless( { 'address' => '127.0.0.0.1', 'port' => '8085' }, 'Common::IPPortDefinition' ) }, 'LocalLB::PoolMember::MemberMonitorStatus' ), bless( { 'monitor_status' => 'MONITOR_STATUS_DOWN', 'member' => bless( { 'address' => '127.0.0.0.1', 'port' => '8085' }, 'Common::IPPortDefinition' ) }, 'LocalLB::PoolMember::MemberMonitorStatus' ), bless( { 'monitor_status' => 'MONITOR_STATUS_DOWN', 'member' => bless( { 'address' => '127.0.0.0.1', 'port' => '8085' }, 'Common::IPPortDefinition' ) }, 'LocalLB::PoolMember::MemberMonitorStatus' ) ], 'LocalLB::PoolMember::MemberMonitorStatus[]' ) ]; 
+4
source share
1 answer

I'm not sure if these member variables are publicly available - I am not familiar with the modules used, so this may break the encapsulation of the LocalLB::PoolMember::MemberMonitorStatus . Before use, check.

 for my $mms ( @{$VAR1->[0]} ) { warn $mms->{monitor_status}; } 

It would be better to check if the MemberMonitorStatus class provides an accessory and, possibly, an iterator for the element monitor state array.

The above was tested simply by inserting the Dumper output in a Perl script with the for loop code implemented based on a data structure search.

(edit: based on F5 web documents in the Google cache, it is possible that MemberMonitorStatus is a simple structure in the base code, presented in Perl as a class with two member variables, but there is no behavior. If so, then this is probably good .)

+4
source

Source: https://habr.com/ru/post/1393067/


All Articles