Hello Monks, I am trying to plot a frequency chart from a log file, that contains the data, about how long it takes for a file to be brought back from tape and how large that file is. For example the bin size for the amount of seconds it takes to bring back a file from tape is 30 secs and will go up in increments of 30 secs and the output looks like this:

seconds No of files 30: 72 60: 93 90: 75 120: 26 150: 18 180: 10 210: 5 240: 2 270: 1 300: 1 330: 2 360: 1 390: 1 450: 1 840: 1 And for the size of files, it's goes up in 25000000 kilobytes Size of file No of files 25000000: 48 50000000: 59 75000000: 30 100000000: 21 125000000: 69 150000000: 13 175000000: 4 200000000: 3 250000000: 1 350000000: 6 425000000: 13 450000000: 3 550000000: 2 675000000: 1 1075000000: 1

The problem is when checking the values it give me. They seem incorrect. I cannot really supply the log file, but I just wanted to know, by looking at the code, is it the correct way to work out the frequency.

$bin_stage = 30; #bin size in number of seconds $bin_filesize = 25000000; #bin size in kb open(READMAP, "$command |") || error_exit("Cannot run readmap, $!"); +#run the readmap command while(<READMAP>) { #loop through the output of the readmap command if (/StageTime/){ @fields = split/\s+/; + #Split the output by white space chop $fields[9]; + # Remove the period after the last digit $diskxStats[$i]{'filesize'}=$fields[2]; $diskxStats[$i]{'ftptime'}=$fields[5]; $diskxStats[$i]{'stagetime'}=$fields[9]; if ( $fields[5] != 0 ){ $diskxStats[$i]{'transferRate'} = $fields[2] / $fields[5]; } else{ $diskxStats[$i]{'transferRate'} = $fields[2]; } if ( $fields[9] != 0 ){ $diskxStats[$i]{'stagerate'} = $fields[2] / $fields[9]; } else{ $diskxStats[$i]{'stagerate'} = $fields[2]; } $i++; } } my $j; ## Build the hash for frequency of stagetime########################## +############################## my $countstage = 0; for ( $countstage = $bin_stage; $countstage <= 3600; $countstage+=$bi +n_stage){ $nextbin = $countstage + $bin_stage; for $i ( 0 .. $#diskxStats ) { if ( $diskxStats[$i]{'stagetime'} >=$countstage && $diskxStats +[$i]{'stagetime'} < $nextbin){ $frequency_stage{$countstage}{'stage_counter'}++; } } } ##Build the hash for frequency of filesizes########################### +############################### my $file_counter= 0; my $countfile = 0; $nextbin = 0; my $array_index = 0; for ( $countfile = $bin_filesize; $countfile <= 1125000000; $countfil +e+=$bin_filesize){ $nextbin = $countfile + $bin_filesize; for $array_index ( 0 .. $#diskxStats ) { if ( $diskxStats[$array_index]{'filesize'} >=$countfile && $di +skxStats[$array_index]{'filesize'} < $nextbin){ $frequency_files{$countfile}{'filesize'}++; } } } my $stage_counter=0; my @sorted_stage = sort { $frequency_stage{$a} cmp $frequency_stage{$b +} } keys %frequency_stage; foreach $i (@sorted_stage) { print "$i: "; foreach $stage_counter ( keys %{ $frequency_stage{$i} } ) { print "$frequency_stage{$i}{$stage_counter}\n"; } } my @sorted_filesizes = sort { $frequency_files{$a} cmp $frequency_file +s{$b} } keys %frequency_files; foreach $i (@sorted_filesizes) { print "$i: "; foreach $file_counter ( keys %{ $frequency_files{$i} } ) { print "$frequency_files{$i}{$file_counter}\n"; } }

Thanks

In reply to Working out frequency statistics with perl by wishartz

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.