On Thu, Dec 29, 2011 at 03:43:19PM +0000, Jonathan Harris wrote:
> Hi All

Hello Jonathan:

(Disclaimer: I stayed up all night playing Skyrim and am running
on about 4.5 hours of sleep.. ^_^)

I think most things have already been addressed, but I think Igor
might have had a bit of trouble making it clear.

> opendir (my $in, $path) or die "Cannot open $dir: $!\n";
> find (\&wanted, $path);
> close $in;
> 
> opendir (my $totalin, $path) or die "Cannot open $dir: $!\n";
> find (\&cleanup, $path);
> close $totalin;

AFAICT, it's completely nonsensical to open a directory file
handle surrounding File::Find::find. I tried to /search the
perldoc (just in case there's some kind of magical optimization
or something) and saw no mention of 'opendir' or 'handle' (except
for the special _ file handle created for stat, lstat, etc..). So
it seems $in and $totalin are completely unnecessary here:
File::Find will worry about opening and processing the
directories for you.

> sub wanted {
>  while ($dircontents = readdir($in)) {

I guess this is why you are opening directory handles above, but
it doesn't really make sense. You're basically only using
File::Find to loop at this point, and very obscurely. :)
File::Find's role in life is precisely to find you all the files
within a directory tree. You're reinventing the square wheel with
your use of opendir and readdir. :)

The wanted subroutine is typically used to either process the
file system tree outright, or store applicable files in data
structures for later processing. E.g.,

use strict;
use warnings;
use File::Find;

my @files;

sub wanted
{
    # Skip dot files and directories.
    return if substr($_, 0, 1) eq '.' || -d $_;

    # If current file is a normal file, push into array for
    # later.
    push @files, $File::Find::name if -f $_;
}

my $path = '.';

find \&wanted, $path;

# Now @files should be filled with a recursive list of files to
# process. E.g.,

for my $file (@files)
{
    my $md5name = $file.'md5';
    # Etc...
}

> my $hex = Digest::MD5->new->addfile($fh)->hex digest;

I assume you meant `hexdigest' here, not 'hex digest'.

> $newname =~ s/\ //;

Ideally if you're going to do something as obscure as this, you
should comment it in both places so future readers and
maintainers understand why it's done, even if they only read one
half of the program.

I think Igor else has already explained how to eliminate this
obscurity though. :)

Regards,


-- 
Brandon McCaig <bamcc...@gmail.com> <bamcc...@castopulence.org>
Castopulence Software <https://www.castopulence.org/>
Blog <http://www.bamccaig.com/>
perl -E '$_=q{V zrna gur orfg jvgu jung V fnl. }.
q{Vg qbrfa'\''g nyjnlf fbhaq gung jnl.};
tr/A-Ma-mN-Zn-z/N-Zn-zA-Ma-m/;say'

Attachment: signature.asc
Description: Digital signature

Reply via email to