in reply to Re^2: A directory diff
in thread A directory diff

Btw, I just noticed that if you happen to pass neither decoration nor directory, $prefix will be undefined and you'll get warnings. Also, the sub is testing definedness of $dir, but the main program is passing an empty string in the last call — doesn't match up. All that considered, the sub should probably read

sub print_diff { my ( $decor, $dir, @filename ) = @_; my $prefix = ''; $prefix .= "$decor " if $opt_plain; $prefix .= "$dir " if defined $dir and length $dir; # awkward :-( print map "$prefix$_\n", @filename; }

That's what I get for not testing my code. :-)

Makeshifts last the longest.

Replies are listed 'Best First'.
Re^4: A directory diff
by hsmyers (Canon) on Aug 27, 2004 at 14:29 UTC
    Well as planned, $decor should never be undefined---but paranoia is a good thing in programming. And certainly the same could be said for $dir. Your note about 'if defined and length' is one of my pet peeves about Perl---you shouldn't have to do two things to make this kind of check. Part of this I suppose is a 'C' hangover---over driven use of zero and such like. Sigh! Thanks again...

    --hsm

    "Never try to teach a pig to sing...it wastes your time and it annoys the pig."