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


In reply to Re: local variable syntax by davido
in thread local variable syntax by yburge

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.