kevind0718 has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks:
I have a simple issue and I read the prior posting that discusses this issue. But still did not get it to work. So you kind assistance is requested.
In my code I need to check if a directory exists under Windows. The directory is specified as follows:
OutFileDirectory = //kbd/tmp/
Within my code I do the test as follows:
if (-d @outFileDirectory ) { print "There is a directory --> " . $outFileDirectory . "\n" ; } else { print "There is a no such directory --> " . $outFileDirectory . +"\n" ; }

The directory exists, but the code reports that it does NOT.
There is a no such directory --> //kbd/tmp
Need a hint as to what I am missing.
Thanks in Advance
kd

Replies are listed 'Best First'.
Re: check if directory exists under windows
by ikegami (Patriarch) on Sep 04, 2007 at 16:10 UTC
    bug | | V if (-d @outFileDirectory ) {

    Use use strict;.

      yep that was it.
      you are brilliant
      kd
Re: check if directory exists under windows
by liverpole (Monsignor) on Sep 04, 2007 at 18:38 UTC
    Hi kevind0718,

    And now that you've got your solution, here's a way to prevent it (or similar) from happening again:

    my $outFileDirectory = "./bin"; + if (-d @outFileDirectory ) { print "There is a directory --> " . $outFileDirectory . "\n" ; } else { print "There is a no such directory --> " . $outFileDirectory . " +\n" ; }

    seems to fail cryptically, as you've observed:

    There is a no such directory --> ./bin

    But if you use strict and warnings:

    use strict; use warnings; + my $outFileDirectory = "./bin"; + if (-d @outFileDirectory ) { print "There is a directory --> " . $outFileDirectory . "\n" ; } else { print "There is a no such directory --> " . $outFileDirectory . " +\n" ; }

    The path to enlightenment is made shorter:

    Global symbol "@outFileDirectory" requires explicit package name at x. +pl line 7. Execution of x.pl aborted due to compilation errors.

    s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/