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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |