About the third error. Unike some cases with the "only used once" warning, Perl is right here.

You've messed up scoping rules, the $MAIN::Log you're trying to access is not the same as the $Log variable above.

$MAIN::Log is the $Log variable of the MAIN package, which can not be your Log for two reasons. Firstly, you declare that $Log with my, so it's a lexical variable, which does not belong to any package, instead, it belongs to the innermost lexical scope in which the declaration is, which is in this case the brace-block labeled MAIN. If you declare a my variable in that block, you can use its name only in that block. Secondly, there's no MAIN package here. The loop label MAIN does not create a package, you have to use the package statement for that. (You might be thinking that you are in package MAIN by default, in the absencse of pkg declarations. Not, that's package main in lc.)

There are two ways you could correct this. The first is that you use a lexical variable. You say my $Log before the opening of the MAIN loop, that way it is valid in the whole script (which is by itself a scope, although the largest one), and then you can refer it with $Log, that is, without a package name later.

The second is that you really use a global variable. In this case, you first have to say package MAIN somewhere, or just write main instead, which is the default package. Then, you change the declaration to our $Log= ... at the assignment, and wow, it's a global variable you can access as $MAIN::log or $main::log depending in what package you've just set.

The first solution is probably appropriate here, I've just written the second so that you know what $MAIN::Log really means here.

(Someone knowing pm please recommend some good tutorial about my and our in this thread. Thx.)


In reply to Re: Newbie Q re: Undefined Value and "only used once" warnings by ambrus
in thread Newbie Q re: Undefined Value and "only used once" warnings by mikeatrcn

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.