|
|
| P is for Practical | |
| PerlMonks |
Re: Converting a C structure to Perlby Fastolfe (Vicar) |
| on Jan 05, 2001 at 07:10 UTC ( [id://50023]=note: print w/replies, xml ) | Need Help?? |
This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.
Remember to close your <code> tags and your question won't be so difficult for us to read. :) If you're looking to find the Perl equivalent of that data structure, another poster already nailed it for you: use a hash. If you're looking to pull in binary data created from that C structure into your Perl program, you probably want unpack. Something like this might do what you're looking for: The format string (described in pack) basically means: 2 bytes of data, two integers, 10 bytes of raw data followed by 9999 bytes of raw data. Other things you might be able to take advantage of: Z for null-terminated strings, c for individual characters/bytes and n/N for "network" short/longs. If you need to generate binary data with information you have, simply change unpack to pack and reverse your arguments around. Pass $id/$secs/etc and get back a binary representation. The format string remains the same. When you say you want a 10,000 byte array, what are you talking about? Are you talking about a C array? I don't know how you expect to judge how many bytes a Perl array will consume. If you want 10,000 elements, that's already been given to you. 10,000 bytes in a string could be done by: "\0" x 10_000 Perhaps you could elaborate and/or use some more appropriate terminology so we can figure out what you mean? Heh. Hope this helps.
In Section
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||||