I recently wrote a script that modifies files and copies them to a different directory. The user can specify on the command line the source and target directories, but I needed to ensure that those directories are different. For example, when running my script, -s specifies the source and -d specifies the destination, but the following command uses the same directory, despite being superficially different:
prod.pl -an -s . -d ../cgi-bin
It seems like a bit of an ugly hack, so if anyone knows of a module with similar functionality, please speak up!

This was written for a WinNT box. Any suggestions for ensuring portability?

Update: This is what I love about this place: see AltBlue's answer below. Short, sweet, and to the point. More importantly, it shows that I should have read the Cwd docs more closely :)

#C:\perl\bin\perl.exe use warnings; use strict; use Cwd; my $source = '.'; my $target = '../cgi-bin'; print sameDirectory( $source, $target ) ? 'Same' : 'Different'; sub sameDirectory { my ( $dir1, $dir2 ) = @_; my $currentDir = getcwd(); chdir $dir1 or die "Can't CD to $dir1: $!"; my $realDir1 = getcwd(); # Need to change back in case they were using relative directories chdir $currentDir or die "Can't CD to $currentDir: $!"; chdir $dir2 or die "Can't CD to $dir2: $!"; my $realDir2 = getcwd(); # Return them to their home directory chdir $currentDir or die "Can't CD to $currentDir: $!";; return $realDir1 eq $realDir2 ? 1 : 0; }

In reply to Test to see if directories are the same by Ovid

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.