Testing for empty value
I have the following code print date times,@date,br; if ($ti1){ print time 1 is not empty; } else { print time 1 is empty; } If there is a value it works but not if there isn't ie: if there is a value it prints time 1 is not empty, but if there is not nothing comes out anyone any ideas? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Testing for empty value
From: mike [EMAIL PROTECTED] I have the following code print date times,@date,br; if ($ti1){ print time 1 is not empty; } else { print time 1 is empty; } If there is a value it works but not if there isn't ie: if there is a value it prints time 1 is not empty, but if there is not nothing comes out anyone any ideas? Sounds strange. Could you send us a small complete script that would display the problem? Something we could run and see that it doesn't print anything even though (you belive) it should. Jenda = [EMAIL PROTECTED] === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Testing for empty value
On 8/5/2004 6:23 PM, Jenda Krynicky wrote: From: mike [EMAIL PROTECTED] I have the following code print date times,@date,br; if ($ti1){ print time 1 is not empty; } else { print time 1 is empty; } If there is a value it works but not if there isn't ie: if there is a value it prints time 1 is not empty, but if there is not nothing comes out anyone any ideas? Sounds strange. Could you send us a small complete script that would display the problem? Something we could run and see that it doesn't print anything even though (you belive) it should. WAG, but maybe this: if ($ti1) { should more properly be written as: if ( defined($ti1) length($ti1) ) { -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Testing for empty value
From: mike mailto:[EMAIL PROTECTED] wrote: : I have the following code : : print date times,@date,br; : if ($ti1){ : print time 1 is not empty; : } : else { : print time 1 is empty; : } : : If there is a value it works but not if there isn't : ie: if there is a value it prints time 1 is not : empty, but if there is not nothing comes out : : anyone any ideas? Works for me. Perhaps you need to show more code post something that produces the error. foreach my $ti1 ( '', 0, 4, undef, 'hello', ) { if ( $ti1 ) { print time 1 is not empty\n; } else { print time 1 is empty\n; } } prints: time 1 is empty time 1 is empty time 1 is not empty time 1 is empty time 1 is not empty -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response