Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

-f file test seems not to work 1

Status
Not open for further replies.

cginewbie

Programmer
Jan 20, 2002
24
US
HI,
I wonder why the -f file test no longer works on some machines, yet others.

I know there is a file called /when i do things lik
if(-f $file){
do this
}
else{
do that
}
where $file ="/
and the "do that" clause always execute, even if I substitute the exact file path with $file. The same program works at my school, yet do not at my home PC, both running windows (but it is not related anyway since it is executed on my Unix host server)

Yet, it is very strange, but I sure this has a cause, and hopefully someone has a solution for it.

thanks
 
The -f operator will fail if it cannot find the file.

The -f test to see if the file is a plain file. Is the file that you are testing on the different machines composed of the same informaion? That could be a possible source of your error?

Another option is just to test if the file exists instead. using he -e operator.

Try this little bit of code just to make sure perl is finding the file and check it out.

if(-e $file){
print &quot;I can find $file<BR> Functions I can do<BR>&quot;
print &quot;Readable<BR>&quot; if -r _;
print &quot;Writable<BR>&quot; if -w _;
print &quot;Executable<BR>&quot; if -x _;
print &quot;File type:&quot;;
print &quot;Text<BR>&quot; if -T _;
print &quot;Binary<BR>&quot; if -B _;

}
else{
print &quot;Where is the file? I am still lost.&quot;
}

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top