APM: Null fields and 100% porcessor

Mike South msouth at fulcrum.org
Wed Apr 2 08:06:20 CST 2003


>From: "Goldilox" <Goldilox at teachnet.edb.utexas.edu>
>Date: Tue, 01 Apr 2003 15:51:53 -0600
>
>dbii at mudpuddle.com writes:
>>>>> while(my @newdata = $newsth->fetchrow_array()){
>>>>> print "Before: $newdata[1] - $newdata[2]\n";
>>>>> $newdata[1] = "N/A" if $newdata[1] eq "";
>>...
>>>>> 1)
>>>>> $newdata[3] = "N/A" if undef $newdata[3];
>>
>>Do you mean you tried:
>>
>> $newdata[3] = "N/A" if ! defined $newdata[3];
>>
>>or what you wrote? undef undefines the value, while defined checks if it is
>>defined. Maybe that was the problem?
>>
>actually I tried 
>> $newdata[3] = "N/A"
> unless
>> defined $newdata[3];
>
>but I thought I was being dumb because defined is only for arrays and I am
>dealing with a scalar variable - so I didn't mention it here. 

Actually, the use of defined() on arrays is deprecated (which I didn't 
know until I looked at 'perldoc -f defined').  defined() is good for
scalars as well as subroutines and I can't remember what else.

I'm not sure how literally to take your code, but, if I'm reading it right,
nothing you do will fix the problem until you move that print statement
down below the 'fix the problem' part:

	while(my @newdata = $newsth->fetchrow_array()){

		# this print statement puts a potentionally uninitialized
		# variable in string, generating a warning 
		print "Before: $newdata[1] - $newdata[2]\n";

		# here is where you are trying to define potential undefs
		$newdata[1] = "N/A" if $newdata[1] eq "";

If you do something like this:

	while(my @newdata = $newsth->fetchrow_array()){

		# every undef in @newdata will get set to "N/A" here
		for (@newdata) { $_ = 'N/A' unless defined $_ };

		print "after: $newdata[1] - $newdata[2]\n";

		...
	}

you won't be interpolating $newdata[1] into the string until after
you have done the check/correction for undefs.

It looks to me like you might have tried more than one thing that
would have fixed your problem, but you were always doing it _after_
you had already used the undef variables in a print(), which generates
the warning you say you are getting.

mike

>It gave me the
>same warnings "uninitialized variable in string or concatenation".
>
>Rhett



More information about the Austin mailing list