apl, I am reading this data from a large report and
stripping out lines and then doing some calculations
based on the input data and then producing an output
file (but the output file is not sorted by the 4th
field).


My code is as follows:

#!/usr/bin/perl use strict; use warnings; ########################################################## # # Parse PS Accounting Data # ########################################################## ## local @ARGV = qw/ may_07_xsd00544.dat /; my %usage; my $uid; my $login; my $cpupr; my $cpunpr; my $cpumin; my $cputot; my $cpupct; my $files = 0; ############################################### # ############################################### for my $file ("may_07_xsd00544.dat") { open (my $fh,"<",$file) or die "Can't open file $file: $!"; ############################################### # ############################################### for my $file ("may_07_xsd00544.dat") { open (my $fh,"<",$file) or die "Can't open file $file: $!"; open (my $OUTGOOD2,">","psapct2.csv") or die "Can't open OUT file: +$!"; print $OUTGOOD2 "Total =,"; while (my $line = <$fh>) { chomp($line); last if ($line =~ /TOTAL COMMAND SUMMARY/); next if (($line =~ /^[a-zA-Z]/) or ($line =~ /^\s*$/) or ($line =~ /^ +\s/)); my ($uid, $login, $cpupr, $cpunpr, @data) = (split("\t",$line)); $cpumin = $cpupr + $cpunpr; if ($login =~ /^TOTAL/) { $cputot = $cpumin; $cpupct = ($cpumin / $cputot)*100; printf $OUTGOOD2 ("%3.1f%%",$cpupct); print $OUTGOOD2 "\n"; } else { $cpupct = ($cpumin / $cputot)*100; printf $OUTGOOD2 ("$uid,$login,%3.1f%%,$cpumin \n" ,$cpupct); } } continue { $files++ if eof; } close $fh or die "Can't close result file: $!"; close $OUTGOOD2 or die "Can't close psapct2.csv data file: $!"; }

In reply to Re^2: How can I sort this data on the fourth field? by country1
in thread How can I sort this data on the fourth field? by country1

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.