I need to check whether a file in a user\'s home directory exists so use file check:
if ( -e \"~/foo.txt\" ) {
print \"yes, it exists!\" ;
}
The home directory for a user is stored in /etc/passwd. The best way to get at the information is the getpw* functions:
#!/usr/bin/perl
use strict;
use warnings;
print "uid:", (getpwuid 501)[7], "\n",
"name:", (getpwnam "cowens")[7], "\n";
To address your specific problem, try this code:
if ( -e (getpwuid $>)[7] . "/foo.txt" ) {
print "yes ,it exists!";
}