IL_bullfinch has asked for the wisdom of the Perl Monks concerning the following question:
Problem description:
when using "-e" command (see example below) to check if file exists, in some cases getting incorrect answer.
While the file actually exists, the "-e" indicates that the file doesn't exists.
Environment:
The file is located in mounted area in NetApp server.
Perl version 5.10.1.
In some cases, the result of Scenario 1 is $is_file_exists=0# Scenario 1, example of the problem: my $is_file_exists = 1; my $db_path = $ST_DB_PATH.$db_name; unless (-e $db_path) { print "The file doesn't exist\n"; $is_file_exists = 0; }
Workaround description:# Scenario 2, example of workaround that solves the problem: my $is_file_exists = 1; my $db_path = $ST_DB_PATH.$db_name; # Adding cat command to solve the "-e" problem `cat $db_path > /dev/null`; unless (-e $db_path) { print "The file doesn't exist\n"; $is_file_exists = 0; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: File Existence using "-e" not always working
by no_slogan (Deacon) on Mar 27, 2014 at 15:58 UTC | |
by tye (Sage) on Mar 28, 2014 at 02:07 UTC | |
|
Re: File Existence using "-e" not always working
by Anonymous Monk on Mar 27, 2014 at 16:57 UTC | |
|
Re: File Existence using "-e" not always working
by jellisii2 (Hermit) on Mar 27, 2014 at 17:34 UTC | |
|
Re: File Existence using "-e" not always working
by Anonymous Monk on Mar 27, 2014 at 17:08 UTC |