Dear esteemed Monks, i have a problem which i cannot figure out. this is also in reguards to the whole program/gui that i am making. (yes i know its taing me forever, but what a learning expirience :) )

Anyways, i have made a script that "should" return the percentage of given characters in a file. the file i am trying to find the amount of characters in, is a binary file thats unpacked with 'H*' for its hex representation, then i search this hex for characters. here is the code:
use File::Slurp; my $file = read_file("file.bin"); my $data = unpack( 'H*', $file ); my $count =()= $data =~ /ff/g; my $size = (stat("file.bin"))[7]; my $dec = $count/$size; my $percentage = ($dec*100); print "$count\n"; print "$size\n"; print $percentage;
it is returning an almost correct value of 10.65, but that is a little higher than what HxD hex editor reports in statistics... which is 10.43. Also i am pretty sure my math is right, but im not the best mathamagician though, lol

Any help would be appreciated :)

In reply to Computing the percentage of certain characters in a file by james28909

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.