Hi, I implemented this code to separate a bunch of files into different categories(%dig and so on). When thought to speed up a little the iteration eliminating form both @img and @vid the items already processed by the last two grep statements, I noted instead that after few iterations the $img variable were returning, at the beginning of the loop, the correct file name but anticipated with the following symbols "?^:". I thought that the loop would affected in some way by this "dynamical" sizing of its array ... what you think about this results ? ... or maybe is my dev ambient "Perl Builder 2.0" for win. ..can you recommend me a different one, more optimized for x64 ? free of charge for instance ? Thanks Simon
....... $footprint_im = 'jpg gif png tiff tif'; $footprint_iv = '^vid.+ 3gp mp4 avi'; $footprint_lnk = 'lnk'; $footprint_im .= ' '.uc $footprint_im; $footprint_im =~ s/ /\$\|/g; $footprint_iv .= ' '.uc $footprint_iv; $footprint_iv =~ s/ /\$\|/g; $footprint_lnk .= ' '.uc $footprint_lnk; $footprint_lnk =~ s/ /\$\|/g; for($i = 1 ; $i <= @ff ;$i++){ next if grep{/$i/}@input; clean($ff[$i-1]); } sub clean{ my $dir = shift; $dir =~ s/\\/\\\\/g; $dir .='\\\\'; opendir F, $dir; @imgg = readdir F; @lnk = grep{/$footprint_lnk/} @imgg; @img = grep{/$footprint_im/} @imgg; # @img = grep{/jpg$|JPG$|gif$|GIF$|png$|tiff$|TIFF$/} @imgg; @vid = grep{/$footprint_iv/} @imgg; closedir F; undef @imgg foreach $img(@img,@vid){ # $img = (@img,@vid)[$i]; # $rr = $img; # $rr =~ s/\(\?\^\:(.+)\)/\1/; # $rr =$1; open my $fh, '<', $dir.$img; my $md5 = Digest::MD5->new->addfile($fh)->hexdigest; close $fh; if ((!$dig{$md5}) and (grep {/$img/} @img)){ $dig{$md5} = $dir.$img ; $dig = values %dig; print R "$md5\t$dir.$img\n"; }elsif ((!$dig_v{$md5}) and (grep {/$img/} @vid)){ $dig_v{$md5} = $dir.$img ; $dig_v = values %dig_v; print R "$md5\t$dir$img\n"; }else{ $del{$md5} = $dir.$img ; } # splice(@img,$i,1) if $rr =~ /$footprint_im/;; @img = grep {!/$rr/} @img; @vid = grep {!/$rr/} @vid; } ...... }
In reply to Strange result on array by solocazzimiei
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |