Q&A

Q1:How is declaring global variables with my any advantage over using regular global variables if I'm writing self-contained scripts to do very simple things?
A1: If the only scripts you write are smaller, self-contained scripts, then you don't really need to use use strict or make sure your variables are declared using my. You'd use my globals if there was a chance for your code being incorporated into someone else's code, even accidentally. Because quite a lot of code has a chance of being used in ways contrary to how you intended it to be used, the use of my globals and use strict is considered a defensive move and good-programming practice. But it is not required.
Q2:Most languages use either lexical or dynamic scope, but not both. Why ...

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.