error print on closed file handle

error print on closed file handle

am 15.09.2011 02:38:49 von Rajeev Prasad

--1091894413-1718256442-1316047129=:60263
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable

plz. advice why am i getting this error?    =0AI have checked:=0Ava=
rilable outfile has proper path/filename=0Aarray allrecords has data  =
 =0Aopen(OUT_FH,">","$outfile");=0Aprint OUT_FH "@allrecords";=0Aclose=
OUT_FH;    =0Aerror:=0Aprint() on closed filehandle OUT_FH at /...=
   =0Athank you.
--1091894413-1718256442-1316047129=:60263--

Re: error print on closed file handle

am 15.09.2011 03:11:49 von William

On Sep 15, 8:38=A0am, rp.ne...@yahoo.com (Rajeev Prasad) wrote:
> plz. advice why am i getting this error?
> =A0
> =A0
> I have checked:
> varilable outfile has proper path/filename
> array allrecords has data
> =A0
> =A0
> open(OUT_FH,">","$outfile");
> print OUT_FH "@allrecords";
> close OUT_FH;
> =A0
> =A0
> error:
> print() on closed filehandle OUT_FH at /...
> =A0
> =A0
> thank you.

Hi Although I don't know the error msg reason, but you can test the
open func is called success . like this
if (! open(OUT_FH, ">", "$outfile")) {
die "Can's open file:$!" ;
}


--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: error print on closed file handle

am 15.09.2011 03:40:12 von jeffpang

CgoKMTUg0YHQtdC90YLRj9Cx0YDRjyAyMDExLCAwNDozOSDQvtGCIFJhamVl diBQcmFzYWQgPHJw
Lm5ldWxpQHlhaG9vLmNvbT46Cj4gcGx6LiBhZHZpY2Ugd2h5IGFtIGkgZ2V0 dGluZyB0aGlzIGVy
cm9yPwo+IMKgCj4gwqAKPiBJIGhhdmUgY2hlY2tlZDoKPiB2YXJpbGFibGUg b3V0ZmlsZSBoYXMg
cHJvcGVyIHBhdGgvZmlsZW5hbWUKPiBhcnJheSBhbGxyZWNvcmRzIGhhcyBk YXRhCj4gwqAKPiDC
oAo+IG9wZW4oT1VUX0ZILCI+IiwiJG91dGZpbGUiKTsKPiBwcmludCBPVVRf RkggIkBhbGxyZWNv
cmRzIjsKPiBjbG9zZSBPVVRfRkg7Cj4gwqAKCllvdSBzaG91bGQgYWx3YXlz IGJlIGFibGUgdG8g
YWRkIGEgIm9yIGRpZSIgZm9yIGNhcHR1cmluZyBleGNlcHRpb25zLgoKb3Bl biBGSCwiPiIsJG91
dGZpbGUgb3IgZGllICQhOwpwcmludCBGSCBAc3RoOwpjbG9zZSBGSCBvciBk aWUgJCE7CgoKLS0K
ICBKZWZmIFBhbmcKICBqZWZmcGFuZ0BtYWlsLnJ1Cg==

Re: error print on closed file handle

am 15.09.2011 03:40:38 von Shawn H Corey

On 11-09-14 08:38 PM, Rajeev Prasad wrote:
> plz. advice why am i getting this error?
>
>
> I have checked:
> varilable outfile has proper path/filename
> array allrecords has data
>
>
> open(OUT_FH,">","$outfile");
> print OUT_FH "@allrecords";
> close OUT_FH;

# You should test all your opens; your problem probably lies there.
# You shouldn't stringify the file name.
# You should use lexical file handles.

open my $out_fh, '>', $outfile or die "could not open $outFile: $!\n";
print $out_fh "@allrecords" or die "could not print to $outfile: $!\n";
close $out_fh or die "could not close $outfile: $!\n";


--
Just my 0.00000002 million dollars worth,
Shawn

Confusion is the first step of understanding.

Programming is as much about organization and communication
as it is about coding.

The secret to great software: Fail early & often.

Eliminate software piracy: use only FLOSS.

"Make something worthwhile." -- Dear Hunter

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: error print on closed file handle

am 15.09.2011 06:04:07 von Rajeev Prasad

--0-399490968-1316059447=:50201
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable

thx. Shawn that fixed the issue. _______________________________=
_=0AFrom: Shawn H Corey =0ATo: beginners@perl.org=0A=
Sent: Wednesday, September 14, 2011 8:40 PM=0ASubject: Re: error print on c=
losed file handle On 11-09-14 08:38 PM, Rajeev Prasad wrote:=0A> plz. =
advice why am i getting this error?=0A> =0A> =0A> I have checked:=0A> varil=
able outfile has proper path/filename=0A> array allrecords has data=0A> =0A=
> =0A> open(OUT_FH,">","$outfile");=0A> print OUT_FH "@allrecords";=0A> clo=
se OUT_FH; # You should test all your opens; your problem probably lie=
s there.=0A# You shouldn't stringify the file name.=0A# You should use lexi=
cal file handles. =A0 open my $out_fh, '>', $outfile or die "could not=
open $outFile: $!\n";   print $out_fh "@allrecords" or die "could not =
print to $outfile: $!\n";   close $out_fh or die "could not close $outf=
ile: $!\n"; =0A-- Just my 0.00000002 million dollars worth,   Shaw=
n Confusion is the first step of understanding. Programming is as=
much about organization and communication=0Aas it is about coding. Th=
e secret to great software:=A0 Fail early & often. Eliminate software =
piracy:=A0 use only FLOSS. "Make something worthwhile."=A0 -- Dear Hun=
ter -- To unsubscribe, e-mail: beginners-unsubscribe@perl.org=0AFor ad=
ditional commands, e-mail: beginners-help@perl.org=0Ahttp://learn.perl.org/
--0-399490968-1316059447=:50201--

Re: error print on closed file handle

am 15.09.2011 08:26:31 von jwkrahn

Rajeev Prasad wrote:
> plz. advice why am i getting this error?

Because the filehandle OUT_FH has NOT been opened correctly!


> I have checked:
> varilable outfile has proper path/filename

How have you checked that?


> array allrecords has data

How have you checked that?


> open(OUT_FH,">","$outfile");

You shouldn't quote variables:

perldoc -q quoting

You should verify that open() worked correctly before trying to use a
possibly invalid filehandle:

open OUT_FH, '>', $outfile or die "Cannot open '$outfile' because: $!";


> print OUT_FH "@allrecords";

Did you really want to interpolate that array?

perldoc -q "Why do I get weird spaces when I print an array of lines?"


> close OUT_FH;
>
> error:
> print() on closed filehandle OUT_FH at /...



John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction. -- Albert Einstein

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/