in reply to uninitialised variable
G'day opaltoot,
Given you're attempting to return one of two constant values ('ab' or 'b') from &test, I don't see the need for $test in that subroutine at all.
Because of the problems with the code, and the fact that you only show calls with no arguments, your intent is unclear. Having said that, I think your old friend the ternary operator can help.
If you want to test whether there were any arguments:
$ perl -E 'sub t { @_ ? "ab" : "b" } say for t(), t(), t(0), t(1)' b b ab ab
If you want to test whether the first argument was TRUE:
$ perl -E 'sub t { $_[0] ? "ab" : "b" } say for t(), t(), t(0), t(1)' b b b ab
— Ken
|
|---|