I completely understand the temptation to comment out strict and warnings so you can get that "feel good it works" experience. Resist that temptation with all your might. The first reason to do so is because "it works" is often an illusion. The only thing you've really gained is the ego boost of not having your mistakes shoved into your face (there is a reason why coders live in a monastery - coding can be a humbling experience!).

The second reason is that you rob yourself of valuable feedback on your coding habits. As you code more and more you will find yourself developing a coding style that is warning proof. Your error rates and warning rates will go down. Just be patient. This learning process takes time.

One way to learn about what the different error messages mean is to put use diagnostics -verbose at the top of your script, i.e.

#!/usr/bin/perl use diagnostics -verbose; use 5.010; use strict; use warnings; open (DATA, 'text.log') or die print $!; binmode DATA #I am trying everything I can while (<DATA>) { @line = split(/ /,$_); $test = $line[2]; if ($test == '<stuff>') { say "$test\n"; } } close DATA;

When diagnostics are turned on, you are likely to get a lot of messages and only the first one or two errors will get a full explanation. If the list is overwhelming, the strategy I find most useful is to:

Following these steps, your first attempt to run the script would have gotten something like this:

DESCRIPTION OF DIAGNOSTICS These messages are classified as follows (listed in increasing ord +er of desperation): (W) A warning (optional). (D) A deprecation (optional). (S) A severe warning (default). (F) A fatal error (trappable). (P) An internal error you should never see (trappable). (X) A very fatal error (nontrappable). (A) An alien error message (not generated by Perl). The majority of messages from the first three classifications abov +e (W, D & S) can be controlled using the warnings pragma. If a messag +e can be controlled by the warnings pragma, its warning category is i +ncluded with the classification letter in the description below. Default warnings are always enabled unless they are explicitly dis +abled with the warnings pragma or the -X switch. Trappable errors may be trapped using the eval operator. See perl +func/eval. In almost all cases, warnings may be selectively disabled + or promoted to fatal errors using the warnings pragma. See warnings. syntax error at Monks/Snippet.pm line 9, near ") {" Global symbol "@line" requires explicit package name at Monks/Snippet. +pm line 10. ... lots more stuff ...

The syntax error on line 9 is due to the binmode line above. It needs to end in a semi-colon, but it does not. If we fix that problem, our diagnostic output looks like this:

DESCRIPTION OF DIAGNOSTICS ...same as above... Trappable errors may be trapped using the eval operator. See perlfunc +/eval. In almost all cases, warnings may be selectively disabled or +promoted to fatal errors using the warnings pragma. See warnings. Global symbol "@line" requires explicit package name at Monks/Snippet. +pm line 9. Global symbol "$test" requires explicit package name at Monks/Snippet. +pm line 10. Global symbol "@line" requires explicit package name at Monks/Snippet. +pm line 10. Global symbol "$test" requires explicit package name at Monks/Snippet. +pm line 11. Global symbol "$test" requires explicit package name at Monks/Snippet. +pm line 13. Execution of Monks/Snippet.pm aborted due to compilation errors (#1) (F) You've said "use strict vars", which indicates that all variab +les must either be lexically scoped (using "my"), declared beforehand + using "our", or explicitly qualified to say which package the global + variable is in (using "::").

Now we get a fuller explanation for that cryptic error message about an "explict package name". Note that this is the same explanation that GrandFather gave you, but you didn't even have to come to the monastery and wait for an answer to get it. It came straight to you.

Best, beth


In reply to Re^3: String evaluation of log files by ELISHEVA
in thread String evaluation of log files by Wes_M

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.