Re: Reading/writing binary

2009-05-12 Thread John W. Krahn
Raymond Wan wrote: Hi Chas., Jenda, On Mon, May 11, 2009 at 6:00 PM, Chas. Owens wrote: On Mon, May 11, 2009 at 04:50, Jenda Krynicky wrote: From: Raymond Wan I'm on a Linux system too; I guess I've used it for so long, I forgot about the situations when binary/text does matter (i.e.,

Re: Reading/writing binary

2009-05-12 Thread Raymond Wan
Hi Chas., Jenda, On Mon, May 11, 2009 at 6:00 PM, Chas. Owens wrote: > On Mon, May 11, 2009 at 04:50, Jenda Krynicky wrote: > > From: Raymond Wan > >> I'm on a Linux system too; I guess I've used it for so long, I forgot > about > >> the situations when binary/text does matter (i.e., Windows

Re: Reading/writing binary

2009-05-11 Thread Chas. Owens
On Mon, May 11, 2009 at 04:50, Jenda Krynicky wrote: > From: Raymond Wan >> On Fri, May 8, 2009 at 8:58 PM, John W. Krahn wrote: >> >> > >> > That depends on the operating system you are using.  I use Linux so there >> > is no difference between "binary" and "text", except for those specific >>

Re: Reading/writing binary

2009-05-11 Thread Jenda Krynicky
From: Raymond Wan > On Fri, May 8, 2009 at 8:58 PM, John W. Krahn wrote: > > > > > That depends on the operating system you are using. I use Linux so there > > is no difference between "binary" and "text", except for those specific > > applications that can't handle "binary" data. If you are o

Re: Reading/writing binary

2009-05-11 Thread Raymond Wan
Hi John, On Fri, May 8, 2009 at 8:58 PM, John W. Krahn wrote: > > That depends on the operating system you are using. I use Linux so there > is no difference between "binary" and "text", except for those specific > applications that can't handle "binary" data. If you are on a system like > DO

Re: Reading/writing binary

2009-05-08 Thread John W. Krahn
Raymond Wan wrote: On 5/8/09, John W. Krahn wrote: [snip] That is equivalent in C to: unsigned char decimal_number = 42; Or another way to write that in Perl is: my $decimal_number = pack 'C', 42; Once you have created the appropriate strings using pack() then just print() them. I se

Re: Reading/writing binary

2009-05-08 Thread Raymond Wan
Hi Chas., On 5/8/09, Chas. Owens wrote: > The place to go is http://perldoc.perl.org, and in your case > http://perldoc.perl.org/functions/pack.html and > http://perldoc.perl.org/functions/unpack.html. You can also get these > docs on your machine by saying > > perldoc -f pack > perldoc -f unpac

Re: Reading/writing binary

2009-05-08 Thread Raymond Wan
Hi John, On 5/8/09, John W. Krahn wrote: [snip] > That is equivalent in C to: > > unsigned char decimal_number = 42; > > Or another way to write that in Perl is: > > my $decimal_number = pack 'C', 42; > > > Once you have created the appropriate strings using pack() then just > print() them.

Re: Reading/writing binary

2009-05-08 Thread Chas. Owens
On Fri, May 8, 2009 at 03:20, Raymond Wan wrote: > Hi Chas, > > On 5/7/09, Chas. Owens wrote: >> You use pack to create a binary value and unpack to read a binary >> value.  So, to write a file containing three 32 bit integers you say > > [snip] > > Thanks for the sample code; that worked exactly

Re: Reading/writing binary

2009-05-08 Thread Raymond Wan
Hi Chas, On 5/7/09, Chas. Owens wrote: > You use pack to create a binary value and unpack to read a binary > value. So, to write a file containing three 32 bit integers you say [snip] Thanks for the sample code; that worked exactly as you said. I wasn't getting anywhere with google; I thought

Re: Reading/writing binary

2009-05-07 Thread John W. Krahn
Raymond Wan wrote: Hi all, Hello, I would like to write binary values to disk (as well as read them) but don't know how to do it. In C-speak, something like this: unsigned int foo = 42; fwrite (&foo, sizeof (unsigned int), 1, stdout); I think the answer involves something with pack and unp

Re: Reading/writing binary

2009-05-07 Thread Chas. Owens
On Thu, May 7, 2009 at 12:24, John W. Krahn wrote: snip > Shouldn't that be either: > > sysopen ... > sysread ... > > Or: > > open ... > read ... > > ? snip If this were C, then yes, but this is Perl and sysread takes a filehandle. Just remember not to mix sysread and readline (or the operator f

Re: Reading/writing binary

2009-05-07 Thread John W. Krahn
Chas. Owens wrote: On Thu, May 7, 2009 at 05:45, Raymond Wan wrote: I would like to write binary values to disk (as well as read them) but don't know how to do it. In C-speak, something like this: unsigned int foo = 42; fwrite (&foo, sizeof (unsigned int), 1, stdout); I think the answer inv

Re: Reading/writing binary

2009-05-07 Thread Chas. Owens
On Thu, May 7, 2009 at 05:45, Raymond Wan wrote: > Hi all, > > I would like to write binary values to disk (as well as read them) but don't > know how to do it.  In C-speak, something like this: > > unsigned int foo = 42; > fwrite (&foo, sizeof (unsigned int), 1, stdout); > > I think the answer in

Reading/writing binary

2009-05-07 Thread Raymond Wan
Hi all, I would like to write binary values to disk (as well as read them) but don't know how to do it. In C-speak, something like this: unsigned int foo = 42; fwrite (&foo, sizeof (unsigned int), 1, stdout); I think the answer involves something with pack and unpack, but I'm completely lost as