Chapter 15. Those Magic Ties and DBM Stuff

Those Magic Ties and DBM Stuff

Tying Variables to a Class

Normally when you perform some operation on a variable, such as assigning, changing, or printing the value of the variable, Perl performs the necessary operations on that variable internally. For example, you don’t need a constructor method just to create a variable and assign a value to it, and you don’t have to create access methods to manipulate the variable. The assignment statement $x=5; doesn’t require any tricky semantics. Perl creates the memory location for $x and puts the value 5 in that location.

It is now possible to bind an ordinary variable to a class and provide methods ...

Get Perl by Example, 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.