-d other file tests
Hello, Adam Theo here; i was wondering if there is something i must declare to use file tests such as -d and -e? i have code which i am working on, and i need to check to see if a file is a directory. if it is, i run a subroutine. i recall having used file tests before, and successfully. i don't recall having to declare anything special to use them, such as 'use File::Test' or something like that. i just used it in the code, like any other core perl function/operator. here is the bit of code relevant to the file tests. through 'print' and data::dumper, i have isolated the root of my problem. it is that the file tests are not being done. the perl interpreter doesn't seem to know to check if the file is a directory, and just skips over it, going on to the final 'else' loop, even though it knows of the file, and can do other stuff with it, just not file tests. sub check_source { my($source_dir, $source_file) = @_; print(Checking $source_dir/$source_file.\n); if ($source_file =~ /^\./) { print(Can't open file '$source_dir/$source_file': System file.\n); } elsif (-d $source_file) { print($source_dir/$source_file is a directory.\n); $source_dir = $source_dir/$source_file; get_sources($source_dir); } elsif ($source_file =~ /(\.xml)$/) { print($source_dir/$source_file is a source file.\n); parse_source($source_dir, $source_file); } else { print(No match!\n); } } thanks in advance! -- /\ Theoretic Solutions (www.Theoretic.com): //\\'Activism, Software, and Internet Services' //--\\ Personal Homepage (www.Theoretic.com/adamtheo/): ][ 'Personal history, analysis, and favorites' ][ Birthright Online (www.Birthright.net): 'Keeping the best role-playing game alive' Email Jabber: Other: -Professional: [EMAIL PROTECTED] -AIM: AdamTheo2000 -General: [EMAIL PROTECTED] -ICQ: 3617307 -Personal: [EMAIL PROTECTED] -Phone: (850)8936047
Re: -d other file tests
On Jul 5, Adam Theo said: sub check_source { my($source_dir, $source_file) = @_; print(Checking $source_dir/$source_file.\n); if ($source_file =~ /^\./) { print(Can't open file '$source_dir/$source_file': System file.\n); } elsif (-d $source_file) { You mean to be checking $source_dir/$source_file, not just $source_file. -- Jeff japhy Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ I am Marillion, the wielder of Ringril, known as Hesinaur, the Winter-Sun. Are you a Monk? http://www.perlmonks.com/ http://forums.perlguru.com/ Perl Programmer at RiskMetrics Group, Inc. http://www.riskmetrics.com/ Acacia Fraternity, Rensselaer Chapter. Brother #734 ** Manning Publications, Co, is publishing my Perl Regex book **
RE: -d other file tests
You are passing the source diretory and file, yet when doing the test you are only doing the source file and not combining the directory and file. Without seeing what you are passing, this would be my first guess. I say this becuase you always pring the two together when you print. Wags ;) -Original Message- From: Adam Theo [mailto:[EMAIL PROTECTED]] Sent: Thursday, July 05, 2001 17:59 To: Perl Beginners Subject: -d other file tests Hello, Adam Theo here; i was wondering if there is something i must declare to use file tests such as -d and -e? i have code which i am working on, and i need to check to see if a file is a directory. if it is, i run a subroutine. i recall having used file tests before, and successfully. i don't recall having to declare anything special to use them, such as 'use File::Test' or something like that. i just used it in the code, like any other core perl function/operator. here is the bit of code relevant to the file tests. through 'print' and data::dumper, i have isolated the root of my problem. it is that the file tests are not being done. the perl interpreter doesn't seem to know to check if the file is a directory, and just skips over it, going on to the final 'else' loop, even though it knows of the file, and can do other stuff with it, just not file tests. sub check_source { my($source_dir, $source_file) = @_; print(Checking $source_dir/$source_file.\n); if ($source_file =~ /^\./) { print(Can't open file '$source_dir/$source_file': System file.\n); } elsif (-d $source_file) { print($source_dir/$source_file is a directory.\n); $source_dir = $source_dir/$source_file; get_sources($source_dir); } elsif ($source_file =~ /(\.xml)$/) { print($source_dir/$source_file is a source file.\n); parse_source($source_dir, $source_file); } else { print(No match!\n); } } thanks in advance! -- /\ Theoretic Solutions (www.Theoretic.com): //\\'Activism, Software, and Internet Services' //--\\ Personal Homepage (www.Theoretic.com/adamtheo/): ][ 'Personal history, analysis, and favorites' ][ Birthright Online (www.Birthright.net): 'Keeping the best role-playing game alive' Email Jabber: Other: -Professional: [EMAIL PROTECTED] -AIM: AdamTheo2000 -General: [EMAIL PROTECTED] -ICQ: 3617307 -Personal: [EMAIL PROTECTED] -Phone: (850)8936047