Subject: | Encode::encode_utf8(undef) returns "", not undef |
In Encode documentation for encode_utf8 function [1] is written:
$octets = encode_utf8($string);
Equivalent to $octets = encode("utf8", $string).
Next, in documentation for encode function [2] is writte:
$octets = encode(ENCODING, STRING[, CHECK])
If the $string is undef, then undef is returned.
So from documentation can be deducted that encode_utf8(undef) should return undef. But instead it returns "" (empty string):
$ perl -MEncode -MData::Dumper -E 'print Dumper Encode::encode_utf8(undef);'
Use of uninitialized value in subroutine entry at Encode.pm line 257.
$VAR1 = '';
Just to check encode("utf8", undef) really returns undef:
$ perl -MEncode -MData::Dumper -E 'print Dumper Encode::encode("utf8", undef);'
$VAR1 = undef;
[1] - https://metacpan.org/pod/Encode#encode_utf8
[2] - https://metacpan.org/pod/Encode#encode