Suppose these two scenarios:
- you are working on this program which has many variables, and you were a bit niggardly naming your variables in a nice, comprehensible concept, you ended up initializing the same variable twice unintentionally and with different values, your program starts working, but the results that're coming out are not what you expect. You could not see that coming because you did not use the strictures.
The most chanted mantras in the Grand Monastery is "use strict, use warnings" . - You have a string variable, $string="hello", however, at some part of your program you wanted to carry out an operation that involves incrementation of a number variable, inadvertently you typed $string++ when you wanted to type $number++, the program worked, giving you a weird result, how would you detect that you were incrementing a string where you should've been incrementing a number unless you switched warnings on?
The most chanted mantras in the Grand Monastery is "use strict, use warnings".
$number = 3;
$number = 4;
$string = "Hello";
$string ++
print "$var\n"; #would print 4 and overwrite 3.
print "$string"; #prints "hellp" and you don't know why "hello" didn'
+t print
If you've used strict and wanrings instead Perl would ask you to intervene and check if there is something it thinks is suspicious "in this case the same variable having been set twice". I am just giving you a very simple example to illustrate this concept but this is the norm of the other data types in Perl too.
The same concept can be stretched further to subroutines naming and conventions so be careful and happy Perl Programming :)
(UPDATED): Made some amendment to cover two scenarios.
Excellence is an Endeavor of Persistence.
Chance Favors a Prepared Mind.
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, details, 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, summary, 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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.