in reply to A directory diff

Nice work, overall. The bit in the middle violates Don't Repeat Yourself, though.

sub print_diff { my ( $decor, $dir, @filename ) = @_; my $prefix = ( ( $opt_plain ? "$decor " : '' ) . ( defined $dir ? "$dir " : '' ) ); print map "$prefix$_\n", @filename; } if ( not( $opt_bonly or $opt_jonly ) ) { print_diff '<', $dirname1, diff( \@dir1, \@dir2 ); } if ( not( $opt_aonly or $opt_jonly ) ) { print_diff '>', $dirname2, diff( \@dir2, \@dir1 ); } if ( $opt_inter or $opt_jonly ) { print_diff '=', '', isect( \@dir1, \@dir2 ); }

Makeshifts last the longest.

Replies are listed 'Best First'.
Re^2: A directory diff
by hsmyers (Canon) on Aug 26, 2004 at 12:55 UTC
    Nice touch! Thanks for lending me your expertise---I'll add it to an update.

    --hsm

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

      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.

        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."