printing 2 arrays to 2 columns.
I have a Perl script that has two arrays - they are related.
I would like to print out the contents into two columns
next to each other.
#!/usr/bin/perl
open(PINGFILE, </home/casper/pingdata.txt") or die " can not open file ";
my @totalfile=<PINGFILE>;
foreach $string(@totalfile) {
if ($string =~ m/(^1\sping)(?=.*max\))/) {
push(usecstring,"$string");
}}
foreach $usecstring(@usecstring) {
if ($usecstring =~ m/(\d{1,20})\susec/){
push(@pingseconds, "$1 ");
}}
foreach $time(@totalfile) {
if ($time =~m/(\w{2}\:\w{2}\:\w{2}\) {
push(@pingtime, "$1 ");
}}
print scalar(@pingtime), "elements in ping array"
print scalar(@pingseconds), "elements in pingseconds array"
I tried this and a variety of join statements -
@newarray=(@pingtime, @pingdate);
foreach (@newarray) {
print "$_\n"
}
But everything I try just prints out consecutively, in one long column - one first, then the other.
I want :
$pingtime[0] $pingseconds[0]
$pingtime[1] $pingseconds[1]
$pingtime[2] $pingseconds[2]
$pingtime[3] $pingseconds[3]
$pingtime[4] $pingseconds[4]
the data structure is below
Tue Jun 8 09:36:11 EDT 2010
1 send(s) took 0 sec 39 usec (0.000039 sec avg, 0.0000039 max)
0 send(s) took more than 0.000050 sec
0 send(s) took more than 0.000050 sec
0 send(s) took more than 0.000050 sec
1 ping(s) took 0 sec 300 usec (0.000039 sec avg, 0.0000039 max)
0 send(s) took more than 0.000050 sec
0 send(s) took more than 0.000050 sec
0 send(s) took more than 0.000050 sec
Tue Jun 8 09:40:11 EDT 2010
1 send(s) took 0 sec 22 usec (0.000039 sec avg, 0.0000039 max)
0 send(s) took more than 0.000050 sec
0 send(s) took more than 0.000050 sec
0 send(s) took more than 0.000050 sec
1 ping(s) took 0 sec 301 usec (0.000039 sec avg, 0.0000039 max)
0 send(s) took more than 0.000050 sec
0 send(s) took more than 0.000050 sec
0 send(s) took more than 0.000050 sec
Tue Jun 8 09:42:11 EDT 2010
Last edited by casperdaghost; 06-17-2010 at 04:24 AM.
|