Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Note: The only reason I put the title as 'use diagnostics' is because I didn't want it to be confused with the Perl documentation page diagnostics.

As many of the monks out there already know, there is a module that catches errors and can potentially help you solve them by giving you examples and explanations of what, possibly, could go wrong.

Just to explain this to you a little more clearly, here is an example that can commonly fail and cause a load of unneeded problems, which no one needs :). This is quite easy though.
#!/usr/bin/perl use diagnostics; my ($q,$w) = 1,2;
Obviously enough, this is a simple error to most Perl users. For those that don't know, the diagnostics module provides some quidelines for you.
Useless use of a constant in void context at c:\windows\TEMP\ + line 3 (#1) (W void) You did something without a side effect in a context that does nothing with the return value, such as a statement that doesn't return a value from a block, or the left side of a scalar comma operator. Very often this points not to stupidity on your part, but a failure of Perl to parse your program the way you thought it would. For example, you'd get this if you mixed up your C precedence with Python precedence and said $one, $two = 1, 2; when you meant to say ($one, $two) = (1, 2); Another common error is to use ordinary parentheses to construct a list reference when you should be using square or curly brackets, for example, if you say $array = (1,2); when you should have said $array = [1,2]; The square brackets explicitly turn a list value into a scalar value, while parentheses do not. So when a parenthesized list is evaluated in a scalar context, the comma is treated like C's comma operator, which throws away the left argument, which is not what you want. See perlref for more on this.
As you can see this gives great help and most of the time will solve the problem. There are also alot of other good warning modules that you should use to solve an unknown error in your script or just help you maintain it. Some of these are.

1. CGI::Carp
2. warnings
3. strict

In conclusion, this is a great module that should be put at the top of your script next to
use strict;
. Great stuff. I recommend it.

In reply to by damian1301

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others cooling their heels in the Monastery: (6)
    As of 2020-06-03 11:47 GMT
    Find Nodes?
      Voting Booth?
      Do you really want to know if there is extraterrestrial life?

      Results (23 votes). Check out past polls.