defined is not meant to be used on arrays and must not be used on arrays in forward-compatible code. It doesn't do anything meaningful.
There's some uncertainty as to what you are trying to do.
Are you trying to return a list (0 or more items)? If so, you probably want to count the number of elements in the array.
print("Number of elements: ", scalar(@rtnVal), "\n");
That will reveal that you do have a bug.
my @rtnVal = undef;
should be
my @rtnVal = ();
or just
my @rtnVal = undef;
Are you trying to return a scalar (1 item or undefined)? If so, you shouldn't be using an array. In fact, your code actually behaves as if @rtnVal is a scalar. If you change it to a scalar $rtnVal, you should get the results you were expecting.
Update: Added second bullet.
In reply to Re: defined or undef
by ikegami
in thread defined or undef
by kevind0718
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |