Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
  • strict can catch some really stupid errors (at compile time), like typos in your variable names. Or accidentally using symbolic references.
  • Warnings can catch things like variables that you forgot to initialize.
  • strict can keep you from doing some bad things, but doesn't prevent you from still writing bad code. It forces you to declare variables with, e.g. my or our or prefixing it with a package name. Variables are usually best declared in as narrow a scope as possible, so they're easy to keep track of, but prefixing a variable with a package name, e.g. main::myvariable, let's you go back down the dark path of having all globals and creating them off in hard to find included (require, do) files and modules, or declaring all of your variables with my at the top of your script.
  • Small scripts (ten lines? one page or less? one-liners? it's up to you) don't really need strict or warnings, but if something goes wrong that you can't figure out, it might be a good idea to turn them on as a first step.
  • If you submit chunks of code for our review here asking for help, and you obviously haven't used strict or warnings, it can be harder to guess at what the problem is.

In reply to Re: Why use strict/warnings? by runrig
in thread Why use strict/warnings? by Mr.T

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2024-04-19 10:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found