Michael Neumann wrote:

> Graham Nicholls wrote:
>> I mentioned before that I'm writing a tool to extract data from a
>> (dataease)
>> database file according to a schema.   In 'C' I'd do something like
>> 
>> struct data
>> {
>>         char header 4;
>>         int recno;
>>         char name[30];
>>         char add_1[30];
>>         ...
>>         unsigned int cr_limit ;
>> } data;
>> 
>> and if I set the compiler options right so the structure was closely
>> packed, I could simply read the file into this structure, and print out
>> the results using
> 
> You need to read sizeof(data) bytes as a String, then unpack it.
> 
> Simple example:
> 
>    C:
> 
>    struct data {
>      long a;
>      long b;
>    };
> 
>    Ruby:
> 
>    str = handle.read(8)
>    a, b = str.unpack('LL')
> 
> Regards,
> 
>    Michael
Excellent - just what I (think!) I want.  I looked at pack, but didn't think
of unpack - you don't know what you don't know, IYSWIM.  The pickaxe book
is great, but its a reference - I'd love to see "Text Processing in Ruby"
or something similar (I've got "Text Processing in Python", but Ruby is
much nicer , IMO, but don't crosspost to c.l.python!).  Thank you.
GN
-- 
The answer's always "Yes".
Now, what was the question?

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----