David T-G wrote at Wed, 12 Jun 2002 15:39:41 +0200:

> I'm trying to be good and so I use "my $variable" rather than making them global, 
>and I prefer to
> not stick little [potentially-confusing] "my" declarations around through the code 
>so I declare my
> vars up front. While some of them might usefully be pre-filled, many of them can 
>happily by left
> declared but undefined, so things like
> 

Wait a moment.
It seems like that:
  - You want to write Perl scripts.
  - You've heard that it is better to use use strict; use warnings;
  - Now Perl's complaining about many no declared variables.
  - You declare them all at the beginning.
  - Now Perl gives warnings because there are some undefined variables.
  - Now you want to assign all variables values like "", 0, () or so for the beginning.

I think, that it is my obligation to warn you 
that use strict; use warnings; wasn't made for that way.

It remembers me to a mafia killer
who has to swear to his mother to have a more christian life style.
So now, he always does a prayer before he kills anybody.
A more christian life style.
(Please don't take it too serious :-)))

use strict; use warnings; wasn't made only to make the Perl Community luckier.
It can help to avoid typical mistakes like
  (a) mispelling of a variable
  (b) using of an undefined variable (what in the most cases isn't wanted)
  (c) side effects without lexical assignments 
      (e.g. to say in a subroutine $i = 5; 
       should'nt influence the $i variable from the main program)
  - ...
  - ...

If the variables are declared at the beginning, 
assigned with the standard values for undefined values.
you only can check (a).

It's a very powerful concept to use variables only where they are needed.
It avoids many side effects.
If there are really some global variables needed,
declare them with the keyword 'our'.

(Another way to remove the ugly warnings from Perl 
 can be done with the CPAN pragma
 use loose;   :-)
)

If there are many scalar values you need globally and
they belongs to a group,
like in the case of MP3-Data,
there's a good chance that a global hash can solve the problem.

Cheerio, 
Janek

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to