in reply to UU-decode unpack of empty string yields undefined value

If encoding and decoding '' did reproduce '', you could then complain that encoding and decoding undef would not reproduce undef (but '' instead)...

Reason is that uuencoding-wise, there is no way to distinguish an empty string from an undefined value, so it's simply an implementation choice which variant appears to be less of an issue in the typical case.

Replies are listed 'Best First'.
Re^2: UU-decode unpack of empty string yields undefined value
by AnomalousMonk (Archbishop) on May 13, 2009 at 15:15 UTC
    If encoding and decoding '' did reproduce '', you could then complain that encoding and decoding undef would not reproduce undef (but '' instead)...
    But isn't the 'standard' (or at any rate the typical) Perl way to handle  undef in numeric and string contexts to coerce it to 0 or the empty string, respectively, and issue warnings as appropriate? Conversely, is there any other numeric or string context in which the empty string is coerced to undef?
    Reason is that uuencoding-wise, there is no way to distinguish an empty string from an undefined value...
    Are you saying by this that the UU-encoding standard specifies no way to encode an empty string, i.e., that an empty string is, literally, 'undefined' in the standard? If this is the case, I would expect  undef to be produced by the encoding step as well as by decoding.

    Perhaps the basic problem here is that I am simply unfamiliar with and do not understand the UU-encoding process.

      Are you saying by this that the UU-encoding standard specifies no way to encode an empty string, i.e., that an empty string is, literally, 'undefined' in the standard?

      Not quite. All I was trying to say is that while Perl variables internally have meta information to tell apart undef from empty, the uuencoding format doesn't have any such provision.  I.e. an empty string encodes to an empty string (nothing, zero bytes), and as it isn't really specified how to encode an undefined value, the nearest approximation would be to also encode it as nothing (zero encoded chars/bytes).

      Now, when you're faced with having to decode that nothing, you cannot tell whether it has been generated by an empty string, or undef. So you just have to make some choice... and it's kind of arbitrary whether you consider decoding nothing into undef or the empty string as more appropriate.