Re: File opening problem

[email protected] ("John W. Krahn")
Newsgroups perl.beginners
Message-ID <[email protected]>
Tatiana Lloret Iglesias wrote:
> Hi all!

Hello,

> i'm running the following dummy program which just opens a file and I get an
> error  (die message)
> 
> #!/usr/bin/perl
> 
> 
> if (  @ARGV[0] eq '' )

@ARGV[0] is an array slice (a list) and it makes no sense to compare a 
list to a string.  It looks like you want something like this:

if ( @ARGV != 1 )  # must have 1 argument

Where you compare an array in scalar context which returns the number of 
elements in that array.

> {
>     print "\nUSAGE:\n\t genenames.pl genes.txt \n\n";
>     exit;
> }
> 
> my $file = $ARGV[0];
> open(FICH,"$file") or die "cannot open $file";
> 
> I've tried to pass the input parameter ARGV[0] with / with \ with relative
> path ... but nothing

Is the file in the current directory?  Does the file name contain spaces 
or any other odd characters?

> any idea?

If you just want to test that the file is readable you can use the -r/-R 
file test:

-r $ARGV[0] or warn "$ARGV[0] is not readable by this user";

perldoc -f -X




John
-- 
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.