jcain has asked for the wisdom of the Perl Monks concerning the following question:
I am trying to do some basic formatting for specific output that is being parsed from top. However, I have a syntax error on line 52, near "." I am using perl 5.10.1
I'm sure I am missing something obvious, but I am relatively new with perl and the manual pages don't appear to offer an obvious explanation. I have tried a few other places for the format code, but I continually get the "." syntax error.
#!/usr/bin/perl use strict; use warnings; use English; #use FileHandle; ## Declarations ## my @topps = qx/top -b -n 1/; my @iostatc = qx/iostat -t -m/; my @iostatd= qx/iostat -m -x | grep -v Linux/; my @top; my @topout; ## End Delcarations ## ## Grab top ps info on any processes using cpu ## foreach (@topps) { chomp; if ($_ =~ /^(\s)*\d+.*/) { push @top, $_; } elsif ($_ =~ /^.*:.*/) { # Print out tops header info print "$_\n"; } } # Some simple headers #my @tophat = ( "User", "Command", "CPU%", "Mem%" ); #$topout[0] = [ @tophat ]; foreach (@top) { my $i = 0; my @line = split; if ($line[8] != 0) { my @tmp = ( "$line[1]", "$line[11]", "$line[8]%", "$line[9]%" ); $topout[$i] = [ @tmp ] ; } $i++; } ## End top grab ## ## Format and Print the top info ## foreach my $t (@topout) { my $index = 0; foreach my $ps (@$t) { my $user; my $cmd; my $cpu; my $mem; format STDOUT_TOP = @<<<<<<<<<<<<<<< @|||||||||| @||||| @||||| User Command CPU% Mem% . $^ = 'STDOUT_TOP'; format STDOUT = @<<<<<<<<<<<<<<< @|||||||||| @##### @##### $user, $cmd, $cpu, $mem . $~ = 'STDOUT'; if ($index == 0) { $user = "$ps"; } elsif ($index == 1) { $cmd = "$ps"; } elsif ($index == 2) { $cpu = "$ps"; } elsif ($index == 3) { $mem = "$ps"; } $~ = 'topinfo'; write; $index++; } } ## iostat cpu and device info ## sub bang { for my $i (1..80) { print "#"; } print "\n"; } bang(); foreach (@iostatc) { chomp; print "$_\n"; } bang(); foreach (@iostatd) { chomp; unless ($_ =~ /^[(avg.*)|(\s+\d+.*)]/) { unless ($_ =~ /^\d+/) { print "$_\n"; } } } bang();
Any suggestions are improvements are welcome in addition to solving the formating error.
Thanks.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Format Syntax error on "."
by kcott (Archbishop) on Feb 21, 2012 at 01:03 UTC | |
by jcain (Initiate) on Feb 21, 2012 at 04:39 UTC | |
|
Re: Format Syntax error on "."
by kielstirling (Scribe) on Feb 21, 2012 at 00:54 UTC | |
|
Re: Format Syntax error on "."
by Anonymous Monk on Feb 21, 2012 at 02:08 UTC | |
by bimleshsharma (Beadle) on Feb 21, 2012 at 10:58 UTC | |
|
Re: Format Syntax error on "."
by DrHyde (Prior) on Feb 21, 2012 at 10:36 UTC | |
by Mr. Muskrat (Canon) on Feb 21, 2012 at 23:29 UTC |