On 25/09/2013 20:38, RENATO AUGUSTO CORREA DOS SANTOS wrote:
Hi, all.
I am a very begginer in PERL starting today in this mailing list! :-) I
will try to work especially with Bioinformatics.
I am trying to verify the existence of a file in PERL; however, is seems
not to work. It always returns "The file $file_seqs does not exist!!!".
Do you know where I am making a mistake?
<code>
#!/usr/bin/perl
use strict;
my $file_seqs;
$file_seqs = $ARGV[0];
if (!-e $file_seqs) {
print "The file $file_seqs does not exist!!! \n";
exit(0);
}
else {
print "The file $file_seqs exist!!! \n";
}
Hello Renato and welcome.
You should also *always*
use warnings;
as it will help you to debug your Perl code.
The rest of your program presumably depends on the existence of the
input file, and you need to open and read it. because of this it is
usual to leave it to the `open` statement to check whether there is a
problem of _any_ sort opening the file, so you would write
use strict;
use warnings;
my $file_seqs = $ARGV[0];
open my $fh, '<', $file_seqs or die "Unable to open $file_seqs: $!";
print "The file $file_seqs existsand has been opened\n";
And if there is no such file you would get
Unable to open 'myfile': No such file or directory at
E:\Perl\source\open.pl line 6.
HTH,
Rob
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/