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 2 of 3 Topic 11056 of 11518
Post > Topic >>

Re: File opening problem

by chas.owens@[EMAIL PROTECTED] (Chas. Owens) May 12, 2008 at 09:10 AM

On May 12, 2008, at 09:05, Tatiana Lloret Iglesias wrote:

> Hi all!
>
> 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 '' )
> {
>   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
>
> any idea?
>
> Thanks a lot!
> T

Your code looks like it should work, so  the only thing you can do is  
get perl to tell you why it can't open the file.  The $! variable  
contains the error number/message (depending on context) for system  
calls, so you can say

open my $fh, "<", $file
    or die "could not open $file: $!";

Note the usage of the three argument version of open.  It is safer  
than using the two argument version.  Also note the usage of lexical  
file handles.  The only bareword filehandles you should be using are  
STDIN, STDOUT, STDERR, and DATA.
 




 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 Thu Jul 24 13:03:46 CDT 2008.