Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

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 = ''; 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 END: Interface report on

Comment on Re: multidimensional array printing
Download Code
Replies are listed 'Best First'.
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 hostname hme1 UP hostname END: Interface report on host1
      I need to figure out when a new interface come by and give a new line...

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (11)
As of 2016-02-08 17:00 GMT
Find Nodes?
    Voting Booth?

    How many photographs, souvenirs, artworks, trophies or other decorative objects are displayed in your home?

    Results (277 votes), past polls