in reply to sub returning undef

Have your sub return the empty list return (); or even (someways better) just return; for the error case. Then your array will be empty.

undef is a value. For example,  my @array = (undef) x 5; print scalar @array; will print 5.


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail