andyford had sage advice. What you mostly need, it seems to me is a workplan for debugging code. Start by using your text editors search and replace tool to insert a '#' sign at the start of every line. Then add at the very top, just after you declare perl as your script's interpreter of choice:

print STDERR "Well, I made it to line: ", __LINE__, ".\n";
Then save your changes and run your script. See if that worked. Did it give you your expected output?

If not, debug that. If so, uncomment a small block of code and copy your debug statement just below it. Run your test again.

Feel free to comment out debug statements earlier in the script, if they have told you what they need to. But don't delete them, As your script matures, they may get reworked as log statements and be used again.

As you copy your debug line down past tested and working code, you can make the debug output more informative, say by writing it this way:

print STDERR "At line: ", __LINE__, ", the message type is $2, so we'l +l append to the log.\n"; etc. . . .
Have you examined the logfile you are processing? Does it contain any lines matched by your regex? If you run this file without redirecting its output, do you see any feedback in the console?

You would likely learn quite a bit about your script were you to write conditions to handle exceptions. Robust code includes lots of conditional paths that the programmer expects will never be taken by legitimate data in a production environment. But coding that exception handling will help you see where you perhaps made bad assumptions about what your code is actually doing. A properly handled exception might recover so the script need not terminate. It could add useful debugging information to a log file. At the very least it could die in a loud and descriptive way.

-- Hugh

if( $lal && $lol ) { $life++; }

In reply to Re: Empty output file with Red Hat by hesco
in thread Empty output file with Red Hat by vineet2004

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.