in reply to Re: Test to see if directories are the same
in thread Test to see if directories are the same

-d $s and $s = abs_path($s) or return -1 ; -d $d and $d = abs_path($d) or return -1 ;
Don't write the same code twice. Ever. :)
-d $_ and $_ = abs_path($_) or return -1 for $s, $d;
Except that's using "foo AND bar OR bletch" where it should be using "foo ? bar : bletch", so I'd tighten that up to:
(-d $_) ? ($_ = abs_path($_)) : (return -1) for $s, $d;

-- Randal L. Schwartz, Perl hacker

Replies are listed 'Best First'.
Re: Re: Re: Test to see if directories are the same
by AltBlue (Chaplain) on Jan 18, 2001 at 15:44 UTC
    merlyn: Don't write the same code twice. Ever. :)
    oops. sorry :))

    this gave me an idea: why not give ppl a way to compare N directories? :) here is the test code:

    #!/usr/bin/perl -w use strict; use Cwd 'abs_path'; defined @ARGV and print sameDirectory(@ARGV),$/; sub sameDirectory { (-d) ? $_ = abs_path $_ : return -1 for @_; $_[0] ne $_ and return 0 for @_; 1; }

    --
    AltBlue.