I have a sub which if all goes well returns an array but if a error is encounted returns undef. I belived this to be good style and know that many built in functions do this.
However I encounted some problems with this and could do with your opinions on where I'm going wrong. The following code will demonstrate whats been happening.
I expected "Array is not defined" but get "Exists". I've tried using defined but -w told me that this is depricated for arrays. So why am I getting this unexpected result?&mysub2(mysub1); sub mysub1{ #normally returns an array. #on error return undef; } sub mysub2{ my @array = @_; unless(@array){ print "Array is not defined" #Expected out come }else{ print "Exists"; } }
In reply to sub returning undef by Scarborough
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |