Re: Storing a 32-bit integer in 4 bytes

2002-02-20 Thread Sisyphus


- Original Message -
From: "$Bill Luebkert" <[EMAIL PROTECTED]>

> You need to binmode the FH and pack the data.  Check out pack/unpack
> in perlfunc man page.  Your filesystem may be big-endian or little-endian
> which will also affect it and transporting to a different endian system
> may be problematic (if you're using an existing app.).

Thanks Bill, thanks Dietmar.

Shoulder known that my aversion to pack/unpack would catch up with me one
day :-)

Guess it's time to come to grips with it.

Cheers,
Rob

___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs



AW: Storing a 32-bit integer in 4 bytes

2002-02-20 Thread Dietmar Maurer

You're writing the string "31554399" to the file.

Use something like

print WRITE pack("I", $num);

See perldoc -f pack

Dietmar

> -Ursprüngliche Nachricht-
> Von: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED]]Im Auftrag von
> Sisyphus
> Gesendet: Mittwoch, 20. Februar 2002 09:51
> An: [EMAIL PROTECTED]
> Betreff: Storing a 32-bit integer in 4 bytes
>
>
> Hi,
>
> Can a 32 bit integer be written to a file in such a way that it
> is stored in
> only 4 bytes ?
>
> I thought that binmoding the filehandle might do this - but  I'm finding
> that a number such as 31554399 is consuming 8 bytes (one byte for each
> digit), irrespective of whether the filehandle has been binmoded or not.
>
> my $num = 31554399;
> open (WRITE, ">test_file")
> or die "Can't open WRITE: $!";
> binmode WRITE; # or not
> print WRITE $num;
> close (WRITE)
>  or die "Can't close WRITE: $!";
>
> Cheers,
> Rob
>
> ___
> Perl-Win32-Users mailing list
> [EMAIL PROTECTED]
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs




Re: Storing a 32-bit integer in 4 bytes

2002-02-20 Thread $Bill Luebkert

Sisyphus wrote:

> Hi,
> 
> Can a 32 bit integer be written to a file in such a way that it is stored in
> only 4 bytes ?
> 
> I thought that binmoding the filehandle might do this - but  I'm finding
> that a number such as 31554399 is consuming 8 bytes (one byte for each
> digit), irrespective of whether the filehandle has been binmoded or not.
> 
> my $num = 31554399;
> open (WRITE, ">test_file")
> or die "Can't open WRITE: $!";
> binmode WRITE; # or not
> print WRITE $num;
> close (WRITE)
>  or die "Can't close WRITE: $!";


You need to binmode the FH and pack the data.  Check out pack/unpack
in perlfunc man page.  Your filesystem may be big-endian or little-endian
which will also affect it and transporting to a different endian system
may be problematic (if you're using an existing app.).

-- 
   ,-/-  __  _  _ $Bill Luebkert   ICQ=14439852
  (_/   /  )// //   DBE Collectibles   Mailto:[EMAIL PROTECTED]
   / ) /--<  o // //  http://dbecoll.tripod.com/ (Free site for Perl)
-/-' /___/_<_http://www.todbe.com/

___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs



Storing a 32-bit integer in 4 bytes

2002-02-20 Thread Sisyphus

Hi,

Can a 32 bit integer be written to a file in such a way that it is stored in
only 4 bytes ?

I thought that binmoding the filehandle might do this - but  I'm finding
that a number such as 31554399 is consuming 8 bytes (one byte for each
digit), irrespective of whether the filehandle has been binmoded or not.

my $num = 31554399;
open (WRITE, ">test_file")
or die "Can't open WRITE: $!";
binmode WRITE; # or not
print WRITE $num;
close (WRITE)
 or die "Can't close WRITE: $!";

Cheers,
Rob

___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs