Let me expand a bit:
yields just:sub undefined { return; } sub empty { my @array= (); return @array; } my @undefd; my @empty= (); my @dedefd= (1,2,3); @dedefd= undefined(); my @emptied= (1,2,3); @emptied= empty(); my @undef2= undefined(); my @empty2= empty(); print "\@undefd is defined\n" if defined @undefd; print "\@empty is defined\n" if defined @empty; print "\@dedefd is defined\n" if defined @dedefd; print "\@emptied is defined\n" if defined @emptied; print "\@undef2 is defined\n" if defined @undef2; print "\@empty2 is defined\n" if defined @empty2;
@dedefd is defined @emptied is defined
You can have an undefined array but there is no such things as an undefined list value. So you can't pass around arrays by value and successfully worry about whether they are defined or not. To make an array undefined, you have to write undef @array and to have a subroutine do that would require that a reference to the array be passed in.
So you really shouldn't try to have two types of empty arrays/hashes. Unlike strings where there is the empty string and undef, Perl doesn't provide a special value for undefined arrays/hashes and doesn't make it easy for you to provide one of your own.
If I need to distinguish an empty list from an error, then I'd probably return a reference to an empty array for the first case and a "false" value for the second.
- tye (but my friends call me "Tye")In reply to (tye)Re2: Replacement for defined(%)/defined(@)?
by tye
in thread Replacement for defined(%)/defined(@)?
by Masem
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |