in reply to Script Critique

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; }

Replies are listed 'Best First'.
Re^2: Script Critique
by drodinthe559 (Monk) on Jul 21, 2008 at 04:07 UTC
    Thank you all for your feedback, its been helpful. I am a new bee at Perl, so I want try to improve hand over fist as I go and not be content with mediocre code. BTW - I normally use strict, so I'm not sure why it was greyed out. I probably frustrated with getting this to work. Thanks again, drod