2 different outputs of read, simple code but strange output.

N

newsgroupie2003

Hi,
I had trouble with a Perl parsing program not working on two different
machines. I have now boiled it down to the minimal example.
Basically i run the code below on 1) fedora core 3, Perl v5.8.5 and
on 2) Linux ret hat Enterp. Perl v5.8.0.
The code reads 4 bytes from the same file and the outputs are:
1)
length= 156
0
0
9
0

2)
length= 156
0
0
9
114



As bytes are read i can't see how it can be related to endianess.
Does anyone have an idea what could be wrong?

Any help greatly appreciated as i am a bit out of ideas of how to
triangulate the error further.

Cheers
Soren




CODE:

if (!open(GEF, "<".$filename)) {
warn "Can't open file $filename: $!\n";
return 1;
}

print "length= ".read(GEF, $pixel_hdr, 156). "\n";

my $q;
for ($q=0; $q < 4; $q++)
{
my $tempstring = substr($pixel_hdr, 124+$q, 1);
print unpack("c", $tempstring);
print "\n";
}
 
R

robic0

On 26 Nov 2005 01:16:37 -0800, (e-mail address removed) wrote:

Well your opening a file, reading a block into a buffer
then printing a few characters. I know this answer in
ansi C but I'm not sure here. Did you change the read
mode to binary after you opened it?
 
T

Tad McClellan

I had trouble with a Perl parsing program not working on two different
machines. I have now boiled it down to the minimal example.

print "length= ".read(GEF, $pixel_hdr, 156). "\n";


Are you using utf8 on one machine but not on the other?

See the last paragraph of:

perldoc -f read
 
N

newsgroupie2003

Thanks!
The RH9 has UTF set under locale. I used binmode(FH) as is also
recommended elsewhere in this group and it works without problems.

Cheers
Soren
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top