List and Scalar Context
Before we leave arrays behind, I'd like to pause significantly to discuss the subject of context. Context, in Perl, is the notion that different bits of data act differently depending on what you're trying to do with them. Context can be particularly baffling to understand, and if you're confused about context you can end up with results that seem to make absolutely no sense (or bits of other people's scripts that produce results seemingly out of nowhere). On the other hand, when you understand context in Perl, and how different operations use context, you can do very complex things very quickly, which would take several lines of code in other languages.
Note
If you're an experienced programmer and you've been scanning ...
Get Sams Teach Yourself Perl in 21 Days, Second 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.