When you say user gives a max limit (in percentage), is that for all the files in the directory or only the target files in the directory? e.g. say you are supposed to just check 25% (size, not quantity) and 75% of the directory is made up of extensions you are not interested in, does that mean you will scan all of the files with extensions you are interested in?
I can give you one approach (assuming the max limit given by user is for % of files that match extension (not % of all files):
Use File::Find to find all files with extensions you are interested in.
With the help of "-s" or stat() to get the file sizes, build a data structure that looks like this:
$myFiles = {
"dir1" => { filelist => [ { filename => "file1.txt", size => 123 },
{ filename => "file2.doc", size => 456 },
+],
dir_size => 579, },
...
};
Iterate through each directory in this structure.
For each random file in "filelist" (can use Shuffle in List::Util for this), scan/process file as long as sum of size of files processed in the directory does not exceed the user supplied percentage of dir_size.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.