Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: New Monks Info Page

by Lexicon (Chaplain)
on Jun 11, 2001 at 05:26 UTC ( [id://87382]=note: print w/replies, xml ) Need Help??


in reply to New Monks Info Page

"We believe there are no stupid questions, just stupid answers."

Not to be overly critical, but I really don't like that line. The "just stupid answers" part might discourage people from answering questions, or give them the impression that we're a bunch of jerks who aren't really funny. I personally can't think of an ending that I really like on it, though I would like some really funny catch phrase.


I would turn #4 into the following:

4. Please, please, please use the following

Study these these pragmas and try putting them in your code. They help pinpoint errors, and give explanations about what's wrong, and might even explain how to fix it.
#!/usr/bin/perl -w # Equivalent to use warnings; see below.
use strict;        # Enforces safer, clearer code.
use warnings;      # Detects common programming errors 
use diagnostics;   # Explains how to fix alerts from use warnings;

use strict; is useful mostly because, like in C or Java, it forces you to declare all your variables before use. This eliminates errors from misspelled variables and encourages the programmer to structure his/her program clearly. It also prevents some tricky things with references and subroutines.

use warnings; (or almost equivalently the -w command line switch) and use diagnostics; are closely related pragmas. use warnings; detects a ton of non-fatal errors caused by syntax mistakes, context misperceptions, etc... use diagnostics; can usually tell you how to fix these problems. These two pragmas especially benifit those new to Perl who are not yet familiar with Perl's idiosyncracies.


Update: I would provide the basic definitions here because getting a new user to start reading Perl's massive amounts of not particularly intuitive documentation is asking quite a lot. Start them out slowly, while they're still feeling their way around.

Replies are listed 'Best First'.
Re: Re: New Monks Info Page
by chipmunk (Parson) on Jun 11, 2001 at 21:34 UTC
    -w is not actually equivalent to use warnings. The most obvious difference is that the warnings pragma is only available in perl5.6.0 and later.

    The other, very important difference is that -w is global, while use warnings is lexical. -w will turn on warnings for all the code used by the script, including in other files. use warnings, on the other hand, will only enable warnings for the block in which it occurs. If you put use warnings in your main script, you won't get warnings from the modules that you use.

    It is probably sufficient to recommend -w for new programmers; it works in all versions of Perl, and is the most general way of getting warnings.

      Not so fast. What if beginner is facing some lazily written module/code which fails with -w? To avoid frustration, we should suggest that:
      1. -w is lazy, version-independent way to get warnings
      2. if it fails, and they are using perl above 5.6.0, then they should use warnings after failing module was used.

        Point 2 can be hidden in link, named "if -w fails", so only point 1 will be visible.

        I am sure somebody can write it in better english. : )

        Just my $0.02.

        I think we are going to another extreme: from not enough links for newbies, to spending too much time on dicussion about links for newbies....

        Let them to do some homework, to have some fun, too.

      pmas

      To make errors is human. But to make million errors per second, you need a computer.

(tye)Re: New Monks Info Page
by tye (Sage) on Jun 11, 2001 at 22:30 UTC

    A link to my strict.pm for more information about why you should use strict might be appropriate.

            - tye (but my friends call me "Tye")
Re: Re: New Monks Info Page
by zeroquo (Novice) on Mar 07, 2002 at 03:47 UTC
    The use or not use of strict module, depend at the platform and class at,whould you programing the script.
    For example :

    If you write a native service, whith Perl Dev Kit, and use the module "perlsvc" you can't use strict module, but if you write a console program, you can use it.

    Personality, I like use that 3 modules :
    strict, warnings and diagnostics
    , and make a simple "sub" called logdump, at that make a simple file whith all output, its simple remmember for first programmers.

    Enjoy.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://87382]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2024-03-28 18:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found