perl - Display data from an array of objects -
i'm trying display data array of objects obtained using company's api, getting errors when attempt using foreach loop.
i'm using dumper display in array.
print dumper($object);
partial output dumper:
'enable_dha_thresholds' => 'false', 'members' => [ bless( { 'ipv4addr' => '192.168.1.67', 'name' => 'name.something.com' }, 'something::network::member' ), bless( { 'ipv4addr' => '192.168.1.68', 'name' => 'name.something.com' }, 'something::network::member' ) ], 'comment' => 'this comment',
i'm trying extract "members" appears double array:
//this works print $members->enable_dha_thresholds(); //this works print $members[0][0]->ipv4addr; //does not work foreach $member ($members[0]){ print "ip". $member->ipv4addr()."\n"; }
i receive error: can't call method "ipv4addr" on unblessed reference @ ./script.pl line 12.
i'm not sure entirely understand "blessed" vs "unblessed" in perl since new language.
print $members[0][0]->ipv4addr; //this works
so $members[0] array reference.
have dereference array:
foreach $member ( @{ $members[0] } ){ print "ip". $member->ipv4addr()."\n"; }
the error refering "unblessed reference" tells you aren't using object; rather provide array-reference, isn't same :)
hth, paul
Comments
Post a Comment