Tom Phoenix wrote: > On 3/13/07, Dharshana Eswaran <[EMAIL PROTECTED]> wrote: > >> I was going thro the topic "Accessing packed data structures" in the Perl >> Complete Reference Book. I came across this example: >> >> struct utmp { >> char ut_user[8]; /* User login name */ >> char ut_id[4]; /* /etc/inittab id */ >> char ut_line[12]; /* device name */ >> short ut_pid; /* process ID */ >> short ut_type; /* type of entry */ >> struct exit_status ut_exit; /* The exit status of a process */ >> /* marked as DEAD_PROCESS. */ >> time_t ut_time; /* time entry was made */ >> }; >> >> For the above structure: >> >> The pack template given was "a8a4a12ssssl". >> >> I am, somehow, not able to understand how to generate the pack >> template from >> the structure's data types. > > The pieces match up this way: > > char ut_user[8]; /* User login name: a8 */ > char ut_id[4]; /* /etc/inittab id: a4 */ > char ut_line[12]; /* device name: a12 */ > short ut_pid; /* process ID: s */ > short ut_type; /* type of entry: s */ > struct exit_status ut_exit; /* The exit status of a process */ > /* marked as DEAD_PROCESS: s s */ > time_t ut_time; /* time entry was made: l */ > > A char array becomes an a42, with the number being the length of the > array. A short becomes s, and a long becomes l. (You do need to know > something about how C stores data in memory. Note that exit_status and > ut_exit are two variables, even though they are declared on the same > line; that's why there are two s's in the comment.)
No, exit_status is an identifier and ut_exit is the variable. In C it is declared something like: struct exit_status { short one; short two; }; And is used something like: struct exit_status variable_1, variable_2; See the C Reference Manual at: http://cm.bell-labs.com/cm/cs/who/dmr/cman.pdf John -- Perl isn't a toolbox, but a small machine shop where you can special-order certain sorts of tools at low cost and in short order. -- Larry Wall -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/