Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: multidimensional array printing

by Anonymous Monk
on Aug 26, 2012 at 12:28 UTC ( #989814=note: print w/ replies, xml ) Need Help??


in reply to multidimensional array printing

my $ifstatus = 'UP'; my $ip_count = 0; my $ipaddr = 'xxx.xxx.xxx.xxx'; my $interface_name = 'hme0'; push @dat, [$interface_name, $ifstatus]; $dat[$ip_count][2] = $ipaddr; print "START: Interface report on $hostname\n"; for (my $i = 0 ; $i <= $#dat ; $i++) { for (my $j = 0 ; $j <= $#{$dat[$i]} ; $j++) { print "$dat[$i][$j] "; } print "\n"; } print "END: Interface report on $hostname\n"; __END__ START: Interface report on hme0 UP xxx.xxx.xxx.xxx END: Interface report on


Comment on Re: multidimensional array printing
Download Code
Re^2: multidimensional array printing
by Anonymous Monk on Aug 26, 2012 at 17:31 UTC
    Why not simply like this:
    print "START: Interface report on $hostname\n"; print join(" ", map @{$_}, @dat) . "\n"; print "END: Interface report on $hostname\n";
      Or much simple:
      print "@{$_}\n" for @dat;
      Almost there, here is the output with your suggestion:
      START: Interface report on host1 hme0 UP xxx.xxx.xxx.xxx hostname hme1 UP xxx.xxx.xxx.xxx hostname END: Interface report on host1
      I need to figure out when a new interface come by and give a new line...

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2015-07-07 03:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (86 votes), past polls