8.1 If We Could Talk to the Animals...Obviously, the castaways can't survive on coconuts and pineapples alone. Luckily for them, a barge carrying random farm animals crashed on the island not long after they arrived, and the castaways began farming and raising animals.Let's let those animals talk for a moment: sub Cow::speak { This results in: a Cow goes moooo! Nothing spectacular here: simple subroutines, albeit from separate packages, and called using the full package name. Let's create an entire pasture: sub Cow::speak { This results in: a Cow goes moooo! Wow. That symbolic coderef dereferencing there in the body of the loop is pretty nasty. We're counting on no strict 'refs' mode, certainly not recommended for larger programs.[1] And why was that necessary? Because the name of the package seems inseparable from the name of the subroutine you want to invoke within that package.[1] Although all examples in this book should be valid Perl code, some examples in this chapter will break the rules enforced by use strict to make them easier to understand. By the end of the chapter, though, you'll learn how to make strict-compliant code again. Or is it? |