You've already got some good responses, I just wanted to clarify terminology.
I need to differentiate an empty array from an uninitialized one.
There is no difference, an uninitialized array is empty. There is a difference between an empty array and an array of one or more undef values, but:
my $str_two = ".5,,0,1," ; ... for $str_two the undefined element is skipped
As already pointed out by jwkrahn, in this case, the elements returned by split will not be undefined (undef), instead they will be empty strings. Although both are evaluated as "false" by perl (Truth and Falsehood), and undef evaluates to an empty string, it will normally warn when being evaluated as a string, and also testing with defined will show the difference between the two.
the resulting array is empty (or may I say "undefined")
I would recommend not calling an empty array "undefined", because that term is usually reserved for undef, which only applies to scalars like the elements of an array - but an empty array doesn't have any!
Is there a proper way to work around this problem with Perl 5?
In your last post from over a year ago, you asked about how to handle CSV data, and I recommended Text::CSV. Let me repeat that recommendation again, since it will properly distinguish between the cases of "" vs. ",,,,", and in the latter case it can even return an array of undef values, if you enable its blank_is_undef option (there is even empty_is_undef).
Update 2019-08-17: Updated the link to "Truth and Falsehood".
In reply to Re: How to differentiate an empty array from an unitialized one?
by haukex
in thread How to differentiate an empty array from an unitialized one?
by iatros
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |