develooper Front page | perl.beginners | Postings from January 2002

Should I use -e -d or opendir ?

Thread Next
From:
K.L. Hayes
Date:
January 9, 2002 18:30
Subject:
Should I use -e -d or opendir ?
Message ID:
127129800461.20020109212812@coppercountry.com
Hello All,

I've found lot's of info on how to check if a file exists but nothing
about checking if a directory exists. I've posted the relevant code
below along with 3 variations of how I "think" it might work. If
somebody could point to the one that is "correct" or knows of a better
way I'd appreciate the help. Thank you.

<CODE_SNIP>
use constant USER_PATH => '/home/~client/htdocs/clients/';
$path = USER_PATH . $personal_key;

## Is This Correct? ##
if (-e "$path") {
        &get_on_with_it }
        else { &errorMsg }

## Or This? ##
opendir(CLIENT, "$path") or die " &errorMsg ";
closedir(CLIENT);
&get_on_with_it

## Or Is It This? ##
if (-d $path) {
        &get_on_with_it }
        else { &errorMsg }
<!CODE_SNIP>

-- 
Best regards,
K.L. Hayes
mailto:perl@coppercountry.com

+=====================================================+
+ "Only two things are infinite, the universe and     +
+ human stupidity, and I'm not sure about the former."+
+                                 -- Albert Einstien  +
+=====================================================+



Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About