References

Perl’s references are similar to C’s pointers, but in operation, they’re more like what you have in Pascal or Ada. A reference “points” to a memory location, but because there’s no pointer arithmetic or direct memory allocation and deallocation, you can be sure that any reference you have is a valid one. References allow OO programming and complex data structures, among other tricks. See the perlreftut and perlref manpages. The Alpaca covers references in great detail.

Complex Data Structures

References allow us to make complex data structures in Perl. For example, suppose you want a two-dimensional array. You can do that,[394] or you can do something much more interesting, like have an array of hashes, a hash of hashes, or a hash of arrays of hashes.[395] See the perldsc (data-structures cookbook) and perllol (lists of lists) manpages. The Alpaca covers this thoroughly, including techniques for complex data manipulation, like sorting and summarizing.

Object-Oriented Programming

Yes, Perl has objects—it’s buzzword-compatible with all of those other languages. OO programming lets you create your own user-defined datatypes with associated abilities, using inheritance, overriding, and dynamic method lookup.[396] Unlike some object-oriented languages, Perl doesn’t force you to use objects. (Many object-oriented modules can be used without understanding objects.) But if your program is going to be larger than N lines of code, it may be more efficient for the programmer (a tiny ...

Get Learning Perl, Fourth Edition 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.