filehandles

S

sivasish

i am getting an error when i am trying to compile folling program in
perl

#!/usr/bin/perl-w
$file= 'siva.pep';
open(FILENAME,$file);
@protein=<FILENAME>;
print @protein;
close FILENAME;

ERROR - readline<>is a closed filehandle FILENAME.........

file "siva.pep" is stored in F DIRECTORY.
I am not able understand the error. .
 
J

Justin C

i am getting an error when i am trying to compile folling program in
perl

#!/usr/bin/perl-w
$file= 'siva.pep';
open(FILENAME,$file);
@protein=<FILENAME>;
print @protein;
close FILENAME;

ERROR - readline<>is a closed filehandle FILENAME.........

Just because you said open siva.pep doesn't mean siva.pep got opened.

open(FILENAME,$file) or die "Cannot open FILENAME: $!"

would give you a clue.

"perldoc -f open" for better was to use that function.


Justin.
 
B

Brian McCauley

sivasish said:
i am getting an error when i am trying to compile folling program in
perl

In addition to the other useful advice you've been given it appears
that you have jumped to a conclusion that that this is a compile time
error, and this may have coloured your attempts to understand it.
 
M

Matt Garrish

Justin said:
Just because you said open siva.pep doesn't mean siva.pep got opened.

open(FILENAME,$file) or die "Cannot open FILENAME: $!"

would give you a clue.

"perldoc -f open" for better was to use that function.

Actually, the open command information is a bit too general in scope.
Although it makes reference to the three-argument form (which what I'm
assuming you mean by better ways), as a description of of all the ways
to use open it doesn't push any one method, and certainly not using
scalars over barewords. I thought perlopentut made reference to the
benefits of using the syntax:

open (my $infile, '<', $file) or die "Cannot open $infile : $!";

but even it is lacking. Since it's generally accepted in current
practice that this is the way one should be opening files, shouldn't
the documentation be updated to refllect this fact, or am I missing the
discussion somewhere?

Matt
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top