in reply to Funny if else problem

What you say :
...I am reading a text file with 5 lines in it. Each line contains a variable=value with a new line at the end. Some of these files have a variable that equals nothing, in which case I want the sub sendemailspecial to run. If the two contain values, then sub sendemailnormal.
Unforturnately the if statement does not appear to be working. Thanx for anyone's help and suggestions.


What this seems to me to mean :
I want to parse a file for paired data separated by an equals sign. If I come across a pair where the second datum is undefined, run sendmailspecial. What you're doing, listed with line numbers, in two parts

Part 1 : Parsing the file

#1 do { #2 $firstline=<FILE>; #3 ($name, $value)=split(/=/, $firstline); #4 $value =~ s/^\s+//; #5 $value =~ s/\s+$//g; #6 $value =~ s/\n//g; #7 print "$name\=$value\n"; #8 $data{$name}=$value; #9 } while $.<5;
#1 : the do block strikes me as odd. If the file will always contain exactly 5 lines, just use a while. This do block would be appropriate if you needed to skim off a header of some sort, but for the data you described, this is more effort than you need.

#4- #6 : the space removal regexes are fine. Why did you choose to use a regex to delete newlines rather than using chomp?

#8 : hash storage. I worry that you could clobber a hash entry, but this probably isn't a concern in your scenario.

Part 2 : Business Logic

#1 if ($data{'SONUMBER'} eq "" || $data{'SALESPERSON'} eq "") { #2 $data{'SONUMBER'}="No S.O. attached"; #3 $data{'SALESPERSON'}="No salesperson assigned"; #4 &sendemailspecial; #5 } else{ #6 &sendmailnormal; #7 } #8 #9 unlink $currentfile;
#1 : this if statement makes a few assumptions which makes me uncomfortable. How do you know that SONUMBER and SALESPERSON are really there?

I would use something like : if ($hash{key}= "" || !defined $hash{key})
or
unless (defined $hash{key} and $hash{key} ne "")
just to make sure that we do the special emailing if the keys aren't there at all.

#9 : Please close files before unlinking them.

To answer your question, your if statement is probably defective. Make sure you check for definedness as suggested.