http://www.perlmonks.org?node_id=1076072


in reply to Question on "my" in the variables

Simply stated, “the real objective here is:

When you are about to shoot yourself in the foot(!!) ... it is much better for the computer to go ‘click’ than to go ‘BANG!!’.

If you “simply” declare all variables to be global, then the ever-accommodating “I presume that you know what you are doing” Perl language will generally try its best to accommodate you.   However, you probably would much prefer that it should detect as many of your errors as possible.   Instead of telling Perl that variables should have the widest possible scope, you probably want to be as specific as possible, and then to use strict; use warnings; so that the computer will have the greatest possible chance of detecting your unintended screw-ups.   Instead of letting Perl run amok, let Perl decline to run your code at all.

Execution-speed is really not the point:   no one is in a hurry to get the wrong answers (or, far worse, “unexplainable but obviously-wrong behaviors”) quickly.

Replies are listed 'Best First'.
Re^2: Question on "my" in the variables
by AnomalousMonk (Archbishop) on Feb 25, 2014 at 04:06 UTC

    ... or far, far, far worse, apparently correct behavior that is only discovered (and discovered, inevitably, in full view of your colleagues/boss/client/the world) to be wrong after a program has run for weeks or months and corrupted some vital database or transaction history that can only be corrected with vast effort and expense — if you're lucky and it can be corrected at all!