in reply to Re: perl script to compare two directories
in thread perl script to compare two directories

Thanks for posting. I have two minor suggestions, if you are interested at all.

sub GetFile2 ... sub isAbsPath

If you don't want your users/co-developers to pull their hair out and curse your name into the void for eternity, don't arbitrarily capitalise the first letter of your sub names. Pick a format (any format) and stick to it.

sub isAbsPath { @_ or return 0; my $P = shift; defined $P or return 0; length($P) or return 0; $P = uc(substr(Trim($P), 0, 3)); my $c = vec($P, 0, 8); return 1 if ($c == 47 || $c == 92); return 0 if ($c < 65 || $c > 90); return 0 if (vec($P, 1, 8) != 58); $c = vec($P, 2, 8); return 1 if ($c == 47 || $c == 92); return 0; }

Did you know that perl has regular expressions? That will save all this hard-coding of ord values, etc. eg:

sub isAbsPath { my $path = shift; return 0 unless defined $path; return $path =~ /^([A-Z]:|[\/\\])/ ? 1 : 0; }

You could omit the ternary if you're only interested in a true/false return value. I've only demonstrated this one subroutine but many others could benefit from such simplification.

The alternative is to use a module. For this case, eg is_absolute from Path::Tiny.

The more you code in Perl, the more Perlish your code will become. Enjoy the journey.

Replies are listed 'Best First'.
Re^3: perl script to compare two directories
by harangzsolt33 (Deacon) on Jul 13, 2019 at 11:19 UTC
    Oh, thank you for the suggestions!!

    "sub GetFile2 ... sub isAbsPath
    If you don't want your users/co-developers to pull their hair out..."

    LOL Okay.