use strict...

R

Robin

I know this is a pretty stupid question, maybe, but is it better to
use strict? I have never gotten a concise answer to this question
because there reallty isn't any docs on it.
thanks,
-ro9bin
 
R

Randal L. Schwartz

Robin> I know this is a pretty stupid question, maybe, but is it better to
Robin> use strict? I have never gotten a concise answer to this question
Robin> because there reallty isn't any docs on it.

% perldoc strict

NAME
strict - Perl pragma to restrict unsafe constructs

SYNOPSIS
use strict;

use strict "vars";
use strict "refs";
use strict "subs";

use strict;
no strict "vars";

DESCRIPTION

[...]

You have a strange meaning of "isn't any". Care to elaborate?

print "Just another Perl hacker,"; # the original
 
O

Owen

I know this is a pretty stupid question, maybe, but is it better to
use strict? I have never gotten a concise answer to this question
because there reallty isn't any docs on it.
thanks,
-ro9bin

There are a number of good reasons to use strict, however, in my case
I use it to help in de-bugging and all other side benefits are a
bonus.

90% of my errors are misspelt variables, IE, somwhere you have

# my $blah;

and later you use $blaj by mistake, it will tell you in its own
fashion that $blaj is perhaps a mistake.

Try this program to get get a message that would not be generated if
'use strict' was not used;

=========================

#!/usr/bin/perl

use strict;

my $blah;

$blaj =2;

========================

You should also 'use warnings' as well. They all help




Owen
 
R

RedGrittyBrick

I know this is a pretty stupid question, maybe, but is it better to
use strict?

Yes. I try to make all my (multi-line) programs start

#!/usr/bin/perl
use strict;
use warnings;
I have never gotten a concise answer to this question
because there reallty isn't any docs on it.

The subject is discussed in this newsgroup surprisingly often.

There seems to be a strong consensus for strict and warnings. There is a
respected minority (possibly just one) who argue that `-w` is better
than `use warnings`. Unless you have read and understood the discussion
(and how it applies to your current project) you should 'use warnings'.
 
P

Patrick H.

I know this is a pretty stupid question, maybe, but is it better to
use strict?

I like it because it makes me be constantly aware of scope since I
have to consciously define everything somewhere. That can only help as
your program code gets longer.

Patrick
 
S

sln

[snip]
Since Robin (and, I assume, you) do not know why you would _not_ use strict,
you _should_ use strict. :)

Then it might be better to know circumstances one wouldn't use strict in
relation to vars, subs, refs, performance, debug, production, bugs, versions,
etc ... There has to be a starting point for full understanding.

-sln
 
S

Steve

I know this is a pretty stupid question, maybe, but is it better to
use strict? I have never gotten a concise answer to this question
because there reallty isn't any docs on it.
thanks,
-ro9bin

I've been reading the oreilly book on perl and it says to always use
warnings and strict. It can be a bit frustrating sometimes though.
Like when your program will compile without using strict and won't
when you use it :p. But that's what it's there for! To make sure you
do things right!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top