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;
}
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.