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.


In reply to Format Syntax error on "." by jcain

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.