in reply to defined or undef
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: defined or undef
by Fletch (Bishop) on Oct 30, 2007 at 14:57 UTC | |
|
Re^2: defined or undef
by kevind0718 (Scribe) on Oct 30, 2007 at 15:18 UTC | |
by ikegami (Patriarch) on Oct 30, 2007 at 15:20 UTC | |
by kevind0718 (Scribe) on Oct 30, 2007 at 15:49 UTC | |
by kevind0718 (Scribe) on Oct 30, 2007 at 15:56 UTC |