Jim Gibson <jimsgib...@gmail.com> writes:

> Some comments on your code:
>
> 1. Rather than doing this:
>
>   while ( <$curridx>) { chomp $_; my $current_file = $_;
>
> you should do this:
>
>   while ( my $current_file = <$curridx> ) { chomp($current_file);

Ah cool :)  I really didn't like the way I did that, this is much nicer
:)

> 2. I would return undef from gethash() if the file doesn't exist,
> rather than '~'. Undef is false in a logical test, and can also be
> tested with the define() function.

Hmmmm ... When you run

  perl -e 'if(undef == undef) {print "eq\n";}'

it prints "eq".  I don't know what

    dbupdatehash($hashs_list_new, $current_file, $current_info[0],
                 $current_info[1], gethash($current_file) );

would write into the hashs.list when gethash() returns undef.  I guess
it would fail with an error along the lines that an undefined value
cannot be printed (joined since I changed that) with others.


Working with non-existing files is actually a glitch in the script atm
because when gethash() returns '~' and that is put into the hashs.list,
next time when the non-existing file still doesn't exist, it may be
considered as changed again because dbreadhash() returns (-1, -1, "")
either when the syntax is incorrect or the file isn't listed in the
hashs.list, and getinfo() returns (-100, -100) as an impossible file
size and impossible mtime.

That comes down to the script comparing a "faked" stored hash for the
non-existing file that looks like (-1, -1, "") with another "faked" hash
created for a non-existing file that looks like (-100, -100, "~").  The
non-existing file will then be considered as changed and reported.

Not knowing about 'undef', I did that intentional to work around the
problem of non-existing files letting the scipt fail when it comes
across them.  Maybe that was a bad idea.

So gethash(), getinfo() and dbreadhash() would have to return 'undef' in
some cases.  That breaks dbupdatehash(), so I'd have to check their
return values to skip non-existing files.  I should make the script
write its output to a logfile and make it read a configuration file
telling it which filenames to use to work with.

> 3. You are reading the close.list file for each file tested. It would
> be more efficient to read the close.list file and put the closed file
> names into a hash, and then you can test each file to see if it is in
> that hash, either with the exists() function, or just be testing the
> hash value. A hash evaluates to undef (false) if the key does not
> exist in the hash.

Cool --- I'm reading up about such hashs now.  What if the closed.index
gets really large and needs to be kept in memory for this?

> 4. You can use the join(EXPR,LIST) function here:
>
>   print $file $key . ":" . $size . ":" . $mtime . ":" . $hash . "\n";
>
> and do this instead:
>
>     print $file join(':',($key,$size,$mtime,$hash)), "\n";

sweet :)


-- 
"Object-oriented programming languages aren't completely convinced that
you should be allowed to do anything with functions."
http://www.joelonsoftware.com/items/2006/08/01.html

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to