Forum Moderators: coopster & phranque

Message Too Old, No Replies

perl script printing binary instead of text data

tried buffering the output, etc nothing seems to work

         

jeremy goodrich

1:03 am on Jan 16, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have a command line perl script I'm using for some database work, and when it out puts the data through a template, some of the files are corrupted, eg have binary instead of textual data.

Checked to be sure I'm closing file handles, etc -> that's okay. But every time I run it, between 1 and 4 of the files are corrupt that are being written...not the same files every time, either.

Any ideas?

This is a snippet of the code that I'm using, the one that prints to the file:

[perl]
open(OUT, ">./out/$outfile")¦¦die "could not open $outfile\n $!";
print OUT @template;
close(OUT)¦¦die "could not close $outfile\n";
[/perl]

Robber

12:55 pm on Jan 16, 2003 (gmt 0)

10+ Year Member



I had trouble with images on a Windows platform before (images were corrupted) - I got round it by using binmode() on the FILEHANDLE after the open function.

Not sure this is really the problem for you though.

jeremy goodrich

6:44 pm on Jan 16, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks for that, but it's textual output that I'm dealing with, not binary...

Strange thing is, it's not a buffer issue (far as I can tell) as when I flush it during the loop or the middle of the program, still happens the same way.

On top of that, it's random files that are corrupted on the ouput...never the same ones, on multiple runs of the script.

Anybody else got an idea?

Key_Master

7:26 pm on Jan 16, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



jeremy,

Have your recently installed or upgraded the Alexa toolbar and are you on a *nix server?

jeremy goodrich

7:38 pm on Jan 16, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Nothing to do with alexa :)

And it's being run from a *nix server / with apache....do you think some kind of server hiccup / pause it causing the output error?

I can transfer the whole thing to another box...but that will take some time -> was hoping to fix the problem before trying to reinstall another place.

Key_Master

7:44 pm on Jan 16, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Nothing to do with alexa

Hehe, didn't ask you that. Is it installed on your computer?

Let me be more specific. It's not your script. There is a bug floating around that causes the exact problems and I'm trying to find the source.

jeremy goodrich

7:46 pm on Jan 16, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Er, I meant -> it's not on my computer. Not running toolbars of any kind.

Key_Master

8:29 pm on Jan 16, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



So we can rule out Alexa but not *nix servers. I asked because the first time I ran with Alexa installed on my computer I ran a script that went binary on me which consequently deleted a log file even though the log file was never open to write to. I deleted and reinstalled the script (which did worked for a while thereafter with no problems). Eventually the problem got worse and I got the host involved.

Symptoms: Files can be corrupted or deleted when a cgi process is run. Scripts that have been running fine for years with no problem suddenly go binary and fail. My host also found a self replicating file that eventually caused a space issue on the server.

I should note, I haven't had anymore of these problems (yet) after the host got involved which was several days ago.

cminblues

7:49 am on Jan 26, 2003 (gmt 0)

10+ Year Member



Did you tried using *nix FLOCK command?

A mean of FLOCK, is to avoid simultaneous write accesses to a 'N' file, with consequent 'N' file corruption.

cminblues

Key_Master

8:04 am on Jan 26, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I use flock in all of my scripts so it doesn't have anything to do with that.

cminblues

9:03 am on Jan 26, 2003 (gmt 0)

10+ Year Member



Key_Master..
My question was directed to jeremy [excuse me for not being so clear :)]

I wrote this 'cause I've had a similar issue [my error: not using FLOCK properly] some times ago on a linux server.
Of course maybe this is'nt the same case.

cminblues

cminblues

9:12 am on Jan 26, 2003 (gmt 0)

10+ Year Member



Er.. another [stupid? :)] tip:

try to set '@template' locally in the subroutine, and zeroing this [my @template = ();] at start of sub.