01-14-2009
If you don't use the strict pragma in a Perl programme all the variables you define (or rather introduce) become implicitly package globals that appear in the symbol table.
At first glance this might tremendously ease the coding (for the novice) but this also is hugely error prone, especially to typos.
So if you inadvertently misspell a variable without strict the Perl compiler would silently declare a new package global without the faintest sign of warning, but this most of the times is pretty useless or even detrimental and will break your programme logic since you intended to refer to some previously declared and defined variable.
Instead when you use strict the Perl compiler will immediately abort compilation and issue an error message hinting at the reason and line which violated the syntax.
Besides, it is considered bad programming style to use global variables,
and one should almost always use lexically scoped variables (those declared by my)
Therefore, even the seasoned Perl programmer should always have the use strict; line at the beginning at their code, and that is one vital marker that indicates good Perl code.
9 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Im trying to write a bash script that has an if statment that when the user enters ONLY that exact argument, will echo what follows that conditon.
For example:
for file in $1
do
if
then
Var1=$(cat hello | egrep "that pattern" | awk '{ print $NF }')
cat $Var1
fi
done
Basically,... (3 Replies)
Discussion started by: oxoxo
3 Replies
2. Shell Programming and Scripting
Hi ,
This script working for fine if pass script-name.sh Jul/10/2007 ,I want to pass 20070710(yyyymmdd) .Please any help it should be appereciated.
use Time::Local;
my $d = $ARGV;
my $t = $ARGV;
my $m = "";
@d = split /\//, $d;
@t = split /:/, $t;
if ( $d eq "Jan" ) { $m = 0 }... (7 Replies)
Discussion started by: akil
7 Replies
3. Shell Programming and Scripting
I opened strict.pm and found some not understandable stuff, please let me know if you have any Idea on the same.
1) Line 23 => $bits |= (what is $= here how it affect the statement)
2) Line 36 => $^H (what is that I haven't found any statement on this in google)
3) Line 41 =>... (3 Replies)
Discussion started by: jatanig
3 Replies
4. Shell Programming and Scripting
How can i print the output of a perl script on a unix console and redirect the same in a log file under same directory simultaneously ?
Like in Shell script, we use tee, is there anything in Perl or any other option ? (2 Replies)
Discussion started by: butterfly20
2 Replies
5. UNIX for Advanced & Expert Users
we create a HP-UX software depot with a new perl-modul. after installation of the software depot, the perl module
i can't find with instmodsh in the inventory for installed Perl modules.
- i have learned of using instmodsh command : i find out what modules are already installed on my system.
... (0 Replies)
Discussion started by: bora99
0 Replies
6. Shell Programming and Scripting
I installed gcc4 today using setup.exe from cygwin. However, I cannot run any of my perl program after that. For example,
Run@Run-THINK /home
$ perl Process.pl
Can't locate strict.pm in @INC (@INC contains: /usr/lib/perl5/5.10/i686-cygwin /
usr/lib/perl5/5.10... (0 Replies)
Discussion started by: littledeer
0 Replies
7. UNIX for Advanced & Expert Users
What are the different ways to disable ssh strict checking? I've seen this mentioned a few times but it doesn't seem to be working.
$ ssh -o 'StrictHostKeyChecking no' admin@hostnamehttp://docs.oracle.com/cd/E35328_01/E35336/html/vmcli-ssh.html
Is there a file somewhere in /etc that I could... (4 Replies)
Discussion started by: cokedude
4 Replies
8. Shell Programming and Scripting
How do I get past the error when using strict and GetOpts ?
#!/usr/bin/perl
use strict;
use Getopt::Std;
# Process the command line options
die "Usage: $0 -r <router> -u <username> -p <password> -e <enable password>\n" if (@ARGV < 6);
exit if (!getopts('r:u:p:e:'));
my... (3 Replies)
Discussion started by: popeye
3 Replies
9. Programming
I have reviewed many examples on-line about running another process (either PERL or shell command or a program), but do not find any usefull for my needs way. (Reviewed and not useful the system(), 'back ticks', exec() and open())
I would like to run another PERL-script from first one, not... (1 Reply)
Discussion started by: alex_5161
1 Replies
LEARN ABOUT REDHAT
strict
strict(3pm) Perl Programmers Reference Guide strict(3pm)
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
If no import list is supplied, all possible restrictions are assumed. (This is the safest mode to operate in, but is sometimes too strict
for casual programming.) Currently, there are three possible things to be strict about: "subs", "vars", and "refs".
"strict refs"
This generates a runtime error if you use symbolic references (see perlref).
use strict 'refs';
$ref = $foo;
print $$ref; # ok
$ref = "foo";
print $$ref; # runtime error; normally ok
$file = "STDOUT";
print $file "Hi!"; # error; note: no comma after $file
There is one exception to this rule:
$bar = &{'foo'};
&$bar;
is allowed so that "goto &$AUTOLOAD" would not break under stricture.
"strict vars"
This generates a compile-time error if you access a variable that wasn't declared via "our" or "use vars", localized via "my()", or
wasn't fully qualified. Because this is to avoid variable suicide problems and subtle dynamic scoping issues, a merely local() vari-
able isn't good enough. See "my" in perlfunc and "local" in perlfunc.
use strict 'vars';
$X::foo = 1; # ok, fully qualified
my $foo = 10; # ok, my() var
local $foo = 9; # blows up
package Cinna;
our $bar; # Declares $bar in current package
$bar = 'HgS'; # ok, global declared via pragma
The local() generated a compile-time error because you just touched a global name without fully qualifying it.
Because of their special use by sort(), the variables $a and $b are exempted from this check.
"strict subs"
This disables the poetry optimization, generating a compile-time error if you try to use a bareword identifier that's not a subrou-
tine, unless it appears in curly braces or on the left hand side of the "=>" symbol.
use strict 'subs';
$SIG{PIPE} = Plumber; # blows up
$SIG{PIPE} = "Plumber"; # just fine: bareword in curlies always ok
$SIG{PIPE} = &Plumber; # preferred form
See "Pragmatic Modules" in perlmodlib.
perl v5.8.0 2002-06-01 strict(3pm)