I've never averaged a sub-list, but here is my stab at it. I think that it meets the requirements of CountZero's Step 1. I'm still stuck on step 2:).
#!/usr/bin/perl use strict; use warnings; use File::Find; use File::stat; use List::Util qw(sum min max); my %files; my $root_dir = '/root/Desktop/Recent'; my $min_file_size = 25000; &find_files; &create_and_print_output; sub find_files { print "\nTraversing tree $root_dir...\n\n"; find(\&trav_tree, "$root_dir" ); } sub trav_tree { if ( -e $File::Find::name ) { $files{ 'files' }->{ total } += 1; push @{ $files{ 'files' }->{ sizes } }, stat($File::Fin +d::name)->size; if ( stat($File::Find::name)->size >= $min_file_size ) +{ $files{ 'sizes' }->{ stat($File::Find::name)->si +ze }->{ filename } = $File::Find::name; } } } sub create_and_print_output { my $sum = sum( @{ $files{ 'files' }->{ sizes } } ); my $number_of_files = $files{ 'files' }->{ total }; my $average_file_size = $sum / $number_of_files; my $smallest_file_name = $files{ 'sizes' }->{ min ( keys %{ $ +files{ 'sizes' } } ) }->{ filename }; my $smallest_file_size = min ( keys %{ $files{ 'sizes' } } ); my $biggest_file_name = $files{ 'sizes' }->{ max ( keys %{ $f +iles{ 'sizes' } } ) }->{ filename }; my $biggest_file_size = max ( keys %{ $files{ 'sizes' } } ); printf "Number of files: %d\n", $number_of_files; printf "Average file size: %d bytes\n\n", $average_file_size; + printf "Closest to average file found was %s with a size of % +d bytes\n", $smallest_file_name, $smallest_file_size; print "\n"; }

In reply to Re: Creating a sub-list constrained by an average while maintaining maximum number of original elements by Khen1950fx
in thread Creating a sub-list constrained by an average while maintaining maximum number of original elements by Jack B. Nymbol

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.