Translating C Data Structures into Perl

Perl and C have vastly different ways of dealing with data structures. In C, you can generate complex data structures and precisely control their layout. Perl’s data structures are both simpler (you can’t nest data structures) and more complex (anonymous references). Yet despite these differences, it’s easy to translate almost any C data structure into Perl. Some of the internals and the details may be different, and the syntax is vastly different, but it can be done.

Hashes as Structures

Perl does not have a built-in data type similar to a C structure, but you can make do with a hash. For example, suppose that you need a structure to hold the date. In C, this would be written as

 struct date { /* C Code ...

Get Perl for C Programmers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.