develooper Front page | perl.beginners | Postings from April 2002

RE: Debugging and 'uninitialized value in concatenation' question

Thread Previous | Thread Next
From:
Jenda Krynicky
Date:
April 25, 2002 14:05
Subject:
RE: Debugging and 'uninitialized value in concatenation' question
Message ID:
3CC88B7F.1002.9243EB@localhost
From: "Jason Frisvold" <Jason.Frisvold@corp.ptd.net>
> Ok, shoot me now...  I tried to provide an example and I blew it..
> *grin*  I realize that the locals are block scope..  I know what I
> meant, just didn't say it..  :)

I see. You never know where does the other guy come from. In VB 
(yes I am forced to use THAT) the scope is either whole subroutine 
or whole file or whole application. Aaaaaggggrrrrrr.
 
> I understand that you cannot access a local variable outside it's
> scope..  Hrm.. ok, try this :
> 
> sub dummy {
>  my $a;
>  if ($b == 1) { $a = 2; }
>  print "$a\n";
> }
> 
> Now..  If $b is 1, then $a gets set to 2 and everything is great.
> However, if not, $a stays unintialized (which I believe is null) and I
> get that 'uninitialized value' error...
> 
> I think I'm answering my own question, though...  always initialize
> the variable and stupid stuff like this won't happen...

Yes, you can do it that way. What I ended up doing though is start 
my scripts&modules with

	use strict;
	use warnings;
	no warnings 'uninitialized';

cause I simply hate that warning. Having to write stuff like:

	if (defined $foo and $foo)

Nay thanks.

Jenda

=========== Jenda@Krynicky.cz == http://Jenda.Krynicky.cz ==========
There is a reason for living. There must be. I've seen it somewhere.
It's just that in the mess on my table ... and in my brain
I can't find it.
					--- me

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About