Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > 2 different outputs of read, simple code but strange output.

Reply
Thread Tools

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

 
 
newsgroupie2003@yahoo.dk
Guest
Posts: n/a
 
      11-26-2005
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";
}

 
Reply With Quote
 
 
 
 
robic0
Guest
Posts: n/a
 
      11-26-2005
On 26 Nov 2005 01:16:37 -0800, 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";
> }


 
Reply With Quote
 
 
 
 
Tad McClellan
Guest
Posts: n/a
 
      11-26-2005
<> 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
Perl programming
Fort Worth, Texas
 
Reply With Quote
 
newsgroupie2003@yahoo.dk
Guest
Posts: n/a
 
      11-27-2005
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

 
Reply With Quote
 
Tad McClellan
Guest
Posts: n/a
 
      11-27-2005
<> 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
Perl programming
Fort Worth, Texas
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
rdoc and Rake::RDocTask with different outputs? Pablo Yanez Ruby 0 05-02-2011 04:13 PM
To output values to the same file for different outputs ram Java 4 11-30-2007 11:52 AM
Encryption Tool Query - Same Input, Different Outputs Lucanos Computer Security 2 08-10-2007 12:57 PM
different outputs in gcc and tc Casanova C Programming 9 03-19-2006 10:40 PM
Different outputs in different environments. Raja Kiran Kumar Reddy Sandireddy C Programming 13 09-09-2004 07:55 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57