in reply to Re^3: How to differentiate an empty array from an unitialized one?
in thread How to differentiate an empty array from an unitialized one?

> no logical reason to distinguish between "empty" and "undefined" for scalars

What do you mean by "empty scalar"? The empty string? Note that it's a perfect value which you can print, measure its length, match against a regex, etc. Undefined value, on the other hand, means the value is missing. If you need to have a special value for "missing value" for the whole array, use an array reference, and assign undef if the whole array is "undefined".

($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
  • Comment on Re^4: How to differentiate an empty array from an unitialized one?
  • Download Code

Replies are listed 'Best First'.
Re^5: How to differentiate an empty array from an unitialized one?
by dsheroh (Monsignor) on Jul 11, 2018 at 07:37 UTC
    You cut off the quote at an unfortunate place. I see plenty of reasons for scalars to distinguish between empty (string) and undefined. What I see no logical reason for is that scalars make that distinction and arrays don't. It makes obvious sense to either have undef for both or have undef for neither, but what's the reasoning behind only doing it for one and not the other?

    Anyhow, as you said, you can definitely work around it using references, no problem there. The way Perl implements it is perfectly usable. It just seems strange to me that scalars have a special "missing value" value, but arrays don't.