From: Michael Neumann Date: 2005-07-06T17:48:00+09:00 Subject: Re: Reading arbitrary data into a c-like structure 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