in reply to local variable syntax
Welcome BAAAACK! We are happy to have you participate here. But if you plan to post in the future, have a look at Writeup Formatting Tips. Your post, the way it's currently (un)formatted makes it next to impossible for people to recognize the code you've taken the time to show us. The Janitors can (and probably will) clean it up for you. But you're better off cleanly formatting your posts in the first place, so they'll be just how you want them, and so people can actually answer them.
As for your question, I know that others have pointed out a few articles to examine. I just wanted to add a comment or two.
First, learn to use strict;. This will force you to use lexical variables (my variables) instead of globals. Starting down that road is taking the first step down the road of success. Next, understand that local simply pushes a package global's current value out of sight onto a sort of internal stack, allowing you to give it a new value such that when the "local" version eventually passes out of scope, the original value is restored. ...it's a little more complex than that, but that's the general idea. This really isn't what you want, most of the time. The best use for local is to ensure that changes you make to Perl's special variables don't propigate beyond the narrowest scope possible. There are, of course, other uses, but none of them are considered beginning topics.
On the other hand, my variables (lexical variables) are truely local to the lexical scope in which they're declared and defined. That's the compartmentalization that you need when developing scripts beyond a dozen or so lines long. Take the time to become familiar with how they work, and you'll be well on your way to a successful learning experience.
Dave
|
|---|