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:

$_ = ...; # binary data in $_ my ($id, $secs, $version, $misc, $data) = unpack("a2iia10a9999", $_);
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 reply to Re: Converting a C structure to Perl by Fastolfe
in thread Converting a C structure to Perl by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.