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

RE: Debugging and 'uninitialized value in concatenation' question

Thread Previous | Thread Next
Jenda Krynicky
April 25, 2002 14:05
RE: Debugging and 'uninitialized value in concatenation' question
Message ID:
From: "Jason Frisvold" <>
> 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.


=========== == ==========
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 Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About