in reply to Undefined vs empty string
Depends somewhat on what you are going to do in the body og the if, but defined and length will generally ensure that a variable is defined and contains something; so negate that:
say "'$_'", ' ', !(defined and length) ? 'go' : 'nogo' for undef, '', +0, 'fred';; Use of uninitialized value $_ in concatenation (.) or string at (eval +16) line 1, <STDIN> line 8. '' go '' go '0' nogo 'fred' nogo
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Undefined vs empty string
by Anonymous Monk on Jun 05, 2013 at 02:48 UTC | |
by BrowserUk (Patriarch) on Jun 05, 2013 at 03:16 UTC | |
by Tux (Canon) on Jun 05, 2013 at 06:05 UTC | |
by BrowserUk (Patriarch) on Jun 05, 2013 at 11:16 UTC | |
by Tux (Canon) on Jun 05, 2013 at 11:21 UTC | |
| |
by ikegami (Patriarch) on Jun 05, 2013 at 20:00 UTC | |
|