Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Perl Beginners > Re: File openin...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 3 Topic 11056 of 11526
Post > Topic >>

Re: File opening problem

by krahnj@[EMAIL PROTECTED] (John W. Krahn) May 12, 2008 at 11:31 AM

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 (  @[EMAIL PROTECTED]
 eq '' )

@[EMAIL PROTECTED]
 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 ( @[EMAIL PROTECTED]
 != 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
 




 3 Posts in Topic:
File opening problem
tlloreti@[EMAIL PROTECTED  2008-05-12 15:05:54 
Re: File opening problem
chas.owens@[EMAIL PROTECT  2008-05-12 09:10:34 
Re: File opening problem
krahnj@[EMAIL PROTECTED]   2008-05-12 11:31:22 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Jul 25 11:41:38 CDT 2008.