Use Getopt::Long and Pod::Usage to take parameters and output help (I agree with toolic's suggestion to add documentation in POD—see perlpod).

For @results and @temp, I say first of all rename them. Second, instead of storing array references, use hash references with beautifully named elements.

push @results_renamed, { filename => $_, mtime => stat($_)->mtime(), bytes => stat($_)->size(), };

Then your sort and a lot of other things become a lot more legible.

@results_renamed = sort { $a->{mtime} <=> $b->{mtime} } @results_renamed;

Check whether rename succeeded and die or warn with $! in the message.

I think $x->[0]->size is a bug. If you'd left use strict in there, I think Perl would have told you so. So use strict!

Say "scalar localtime" explicitly rather than counting on concatenation for the scalar context.

It might be a good idea to be more specific about what files you want to operate on. There's nothing wrong with m/ACH/, but I suspect you mean /^ACH/ or something even more specific. If this is accidentally used somewhere it should not be, what happens?

I prefer anonymous code references over references to named subs that aren't used for anything else.

my @temp; my $post = sub { push @temp, { filename => $_, mtime => stat($_)->mtime } if /USB/ }; find( $post, 'c:/test' );

This way $post is a lexical and does not run the risk of running up against another sub somewhere. You can take that code off into its own sub and be sure it doesn't interfere with anything else.

sub find_usb { my @temp; my $post = sub { push @temp, { filename => $_, mtime => stat($_)->mtime } if /U +SB/ }; find( $post, 'c:/test' ); return @temp; }

In reply to Re: Script Critique by kyle
in thread Script Critique by drodinthe559

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.