Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

printing an array reference

by vedas (Novice)
on Jan 17, 2019 at 03:48 UTC ( #1228673=perlquestion: print w/replies, xml ) Need Help??

vedas has asked for the wisdom of the Perl Monks concerning the following question:

Apologies if this seem like a simple question, I'm working on learning the more advanced topics in perl.

I'm having trouble pulling information out of data an array reference. I'm trying to print data that returned from the aliases method. Would anyone be able to tell me what I'm doing wrong?

#:Code #!/usr/bin/perl # use strict ; #use lib "/var/www/html/monkey/cgi-bin"; use lib "/var/www/html/production/cgi-bin"; # load the WebUI common libraries use Infoblox::WebUI ; use Data::Dumper; my $session = Infoblox::Session->new( master => $address, username => $user, password => $passwd, timeout => $timeout_num, connection_timeout => $conn_timeout ); print "Check:".Infoblox::status_code() . ":" . Infoblox::status_detail +()."\n"; unless ($session) { die("Construct session failed: ", Infoblox::status_code() . ":" . Infoblox::status_de +tail()); } #Get DHCP Host Address object through the session my @retrieved_objs = $session->get( object => "Infoblox::DNS::Host", name => "testone.cnti.com", ); #my @tmp_array = @$_->aliases() for (@retrieved_objs); #print "aliases: " . @tmp_array; print "aliases: " .$_->aliases(),"\n" for (@retrieved_objs); print "dns_name: " . $_->dns_name(),"\n" for (@retrieved_objs); print "ipv4addrs: " . $_->ipv4addrs(),"\n" for (@retrieved_objs); print "comment: " . $_->comment(),"\n" for (@retrieved_objs); print "name: " . $_->name(),"\n" for (@retrieved_objs);: : : :OUTPUT [user1@host perl]$ ./infoblox_test4.pl Check:0:Operation succeeded aliases: ARRAY(0x55f6da24f8f0) dns_name: testone.cnti.com ipv4addrs: ARRAY(0x55f6da243eb0) comment: Standard Network: [TAGS: STATIC;cc.cnti.com] name: testone.cnti.com zone: cnti.com ttl: 300

Replies are listed 'Best First'.
Re: printing an array reference
by NetWallah (Canon) on Jan 17, 2019 at 05:52 UTC
    Try:
    print "aliases: " , join(",",@{ $_->aliases() }),"\n" for (@retrieved_ +objs);

                    As a computer, I find your faith in technology amusing.

      Yes, thank you Sir. Looks like the join worked. I'm a little confused by it, that suggests it is returning an array containing each portion of the name. I was actually expecting it to return an array of FQDNs. I'll have to do more research. Thank you for your assistance.

        In your original post, the line of output "aliases: ARRAY(0x55f6da24f8f0)" is clearly the only output of the statement "print "aliases: " .$_->aliases(),"\n" for (@retrieved_objs);". The fact that there is only one such line tells us that there is only one element in the array @retrieved_objs. The content of that line tells us that the element is a reference to an array. NetWallah's solution starts by dereferencing that reference. The join is his way of formatting that array for printing. Without documentation for your module, I cannot tell you why you have only one object or what that object should contain.
        Bill
Re: printing an array reference
by LanX (Archbishop) on Jan 17, 2019 at 05:01 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1228673]
Approved by Athanasius
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (9)
As of 2019-10-17 18:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?