Mary Anderson wrote: > Hi All, > I know this isn't strictly a cgi problem, but it is arising in a cgi > application. I have a loop which reads certain fields, hashed on names. > Some of my fields hold character strings, some hold numbers. Sometimes > the number field is a blank. I need a test on the field value $fieldValue > which will tell me if my field was blank regardless of whether it holds a > character string or a number. > > I would like to say something like > > $fieldValue = (($fieldValue == 0) or $fieldValue) ? $fieldValue : 'null' > > but perl appears to have a strange interpretation of $fieldValue == 0 if > $fieldValue is a character. > > Thanks > Mary > > I have seen references to a function which will do the trick, but it > is not mentioned in the camel book. >
0 or any other number translates to a string when using the 'eq' operator, so you could check to see whether $fieldValue is blank using, if ($fieldValue eq '') { # $fieldValue is defined but empty } --or-- if ($fieldValue ne '') { # $fieldValue is not blank (but may be false) } You could also check using the length function, but I wouldn't bother unless for some reason the above won't work. HTH, http://danconia.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>