On Mon, Jun 7, 2010 at 3:25 PM, Uri Guttman <u...@stemsystems.com> wrote:

> >>>>> "np" == newbie01 perl <newbie01.p...@gmail.com> writes:
>
>  np> I found a better example at a Perlmonk posting and changed it a bit as
>  np> below:
>
>  np> #!/usr/bin/perl
>  np> use strict;
>
> no use warnings. bad. see below.
>  np> use File::Find;
>  np> use File::Spec::Functions;
>  np> #use File::Spec->no_upwards();
>
>  np> #if ($ARGV[0] eq "") { $ARGV[0]="."; }
>  np> if ($ARGV[0] eq "") {
>
> if no arguments are passed on the command line, @ARGV will be
> empty. comparing the first slot to "" will generate a warning. you
> didn't enable warnings so you didn't see it. the proper way is to check
> for any (or too few) elements like this:
>
>        if ( @ARGV < 1 ) {
>
>  np> print "You must specify a directory path ... !!! exiting ... \n";
>
> why tell the user you are exiting. pretty obvious
>
>  np> exit 0;
>  np> }
>
>  np> #...@paths = File::Spec->no_upwards( @paths );
>  np> my @file_list;
>  np> #finddepth ( sub {
>
> don't leave old commented code around unless you have a reason. it makes
> it much harder to read the code.
>
>  np> find ( sub {
>  np> my $file = $File::Find::name;
>  np> # - To select files beginning with DATE
>  np> # if ( -f $file && $file =~ /^DATE_/) {
>  np> # push (@file_list, $file)
>  np> # }
>  np> push (@file_list, $file)
>  np> }, @ARGV);
>
>  np> @file_list = File::Spec->no_upwards( @file_list );
>  np> my $now = time(); # get current time
>
> useless comment. comment on WHY you are getting the time, not that you
> are getting the time. the code say WHAT, comments say WHY.
>
>  np> my $AGE = 60*60*24*14; # convert 14 days into seconds
>
> that doesn't convert anything -- it just calculates a number. also put
> your comments on the line before the code, not on the same line. your
> style makes it noisier.
>
>
>  np> for my $file (@file_list) {
>  np> my @stats = stat($file);
>  np> if ($now-$stats[9] > $AGE) { # file older than 14 days
>
> better as:
>
>        my $file_time = (stat($file))[9] ;
>        if ( $now - $file_time > $AGE) {
>
> i also added horizontal whitespace.
>
> uri
>
> --
> Uri Guttman  ------  u...@stemsystems.com  --------  http://www.sysarch.com--
> -----  Perl Code Review , Architecture, Development, Training, Support
> ------
> ---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com---------
>

Hi Uri,

Thanks for the advise ... very well given ...

How do I exclude the command line argument from the "found" directories ...
??? Or would you recommend using File::Find::Rule to exclude that directory
... ???

The script is supposed to search within that directory but exclude that
directory ... I just want to know if I can exclude it rather than going thru
the entire array and search for an exact match of that command line argument
...

Thanks in advance.

Reply via email to