Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
sub process_file {
    my $dir_configs=$_[0];
    ##optimisation using -d -l -f -s just once for return and also for adding

    #if current "file"(unix terminology) is a directory and the yaml configuration
    #tells us to eliminate directories from the search we do so by returning from the
    #callback
    return if -d $File::Find::name && ! $dir_configs->{dir};

You call stat on the file.

    return if -l $File::Find::name && ! $dir_configs->{link};

You call lstat on the same file.

    return if -f $File::Find::name && ! $dir_configs->{file};

You call stat on the same file again.

    return if -s $File::Find::name < $config->{minsize};

You call stat on the same file again.

    unless($File::Find::name =~  /$dir_configs->{regex}/) {
        if(-d $File::Find::name) {

You call stat on the same file again.

            $File::Find::prune=1;
        }
        return;
    }

    my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
        $atime,$mtime,$ctime,$blksize,$blocks)
    = stat($File::Find::name);

You call stat on the same file again. You declare 13 variables but you are only using one.

    my $last_modif_time=DateTime->from_epoch(epoch=>$mtime);
#    printf "%s %s %s %s\n",
#    $File::Find::name,
#    file2sha1($File::Find::name),
#    -s $File::Find::name,

Commented out but if not you call stat on the same file again.

#    $last_modif_time;

    add_to_db(file2sha1($File::Find::name),$last_modif_time,-s $File::Find::name,$File::Find::name);

You call stat on the same file again. You call add_to_db() which calls stat or lstat three more times.

    #print Dumper $dir_configs;
};

In total you call stat or lstat ten times on the same file (eleven times if you uncomment the printf statement.) You also use $File::Find::name in most places where $_ would have the same effect.

sub process_file { my $dir_configs = $_[ 0 ]; ##optimisation using -d -l -f -s just once for return and also for + adding #if current "file"(unix terminology) is a directory and the yaml c +onfiguration #tells us to eliminate directories from the search we do so by ret +urning from the #callback return if -l && ! $dir_configs->{ link }; # call lstat on current +file to test for symlink my ( $size, $mtime ) = ( stat )[ 7, 9 ]; return if -d _ && ! $dir_configs->{ dir }; return if -f _ && ! $dir_configs->{ file }; return if $size < $config->{ minsize }; unless ( $File::Find::name =~ /$dir_configs->{regex}/ ) { if ( -d _ ) { $File::Find::prune = 1; } return; } my $last_modif_time = DateTime->from_epoch( epoch => $mtime ); # print "$File::Find::name ", file2sha1( $_ ), " $size $last_modif_ +time\n", add_to_db( file2sha1( $_ ), $last_modif_time, $size, $File::Find:: +name ); #print Dumper $dir_configs; }

In reply to Re: scalable duplicate file remover by jwkrahn
in thread scalable duplicate file remover by spx2

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2024-04-26 06:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found