Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"Use of uninitialized value in concatenation (.) or string"

Status
Not open for further replies.

msmonkey

Programmer
Apr 16, 2002
6
US
Does anyone know what would cause the following warning and how to get rid of it?

"Use of uninitialized value in concatenation (.) or string"

I am using Strict in my module.

It happens during the following code:

open (INPUT, "expenses") || die "Error opening expense_categories";

while (<INPUT>) {
chomp;
my($date,$category,$amount) = split (/~/);
print &quot; #error happens here
<tr> <td>$date</td>
<td>$category</td>
<td>\$$amount</td>
</tr>&quot;;
}
close (INPUT);
 
At some point, your split isn't returning three results, and at least one of the three scalars you set by it aren't set at all, and are uninitialized. You're probably getting a few blank table entries, too. You might have a bad data file, or something like a blank line at the end that has no data to split on. You could check that split returned three values like this:
Code:
#instead of this:
my($date,$category,$amount) = split (/~/);

#use this:
my($date,$category,$amount);
if(scalar (($date,$category,$amount) = split (/~/)) == 3) {
[code]
And put your print inside the conditional.

Hope it helps.

----------------------------------------------------------------------------------
...but I'm just a C man trying to see the light
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top