Home > Archive > PERL Miscellaneous > November 2005 > 2 different outputs of read, simple code but strange output.
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
2 different outputs of read, simple code but strange output.
|
|
| newsgroupie2003@yahoo.dk 2005-11-26, 3:58 am |
| 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";
}
| |
| robic0 2005-11-26, 7:56 am |
| On 26 Nov 2005 01:16:37 -0800, newsgroupie2003@yahoo.dk 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?
>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";
> }
| |
| Tad McClellan 2005-11-26, 7:56 am |
| newsgroupie2003@yahoo.dk <newsgroupie2003@yahoo.dk> wrote:
> 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
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
| |
| newsgroupie2003@yahoo.dk 2005-11-27, 7:56 am |
| 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
| |
| Tad McClellan 2005-11-27, 6:58 pm |
| newsgroupie2003@yahoo.dk <newsgroupie2003@yahoo.dk> wrote:
> Thanks!
Thanks for what?
Please quote some context in followups like everybody else does.
(You're welcome, BTW)
> The RH9 has UTF set under locale.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
|
|
|
|
|