in reply to Reason for this discrepancy with scalar?

> encode the PV as "0"

No, @empty returns three internal types

IV = 0 NV = 0 PV = 0x7fb0f957d3c2 "0"

The background is probably that the length of an array is very often used as Boolean in conditions.

(Actually I also expected a dualvar flag to be set, but I'm no expert here.) ²

Perl tends to pre-optimize type castings. I. e. the stringification is already "memorized" to speed up future conversions.

Contrary to Python¹ does it depend on context if a var is seen as integer, float or string.

So yes, adding 0 is the way to go.

FWIW: does this really happen with JSON that the string is preferred? And what happens if you use the first result as string prior to serialization? A PV "1" should be cashed after the first stringification, too!

Hence same problem again.

Cheers Rolf
(addicted to the Perl Programming Language :)
see Wikisyntax for the Monastery

¹) I've seen many type errors in Python, where Perl was just silently DWIM. But this was back in the time I experimented with Python 2.

²) nah, nonsense. Boolean false stringifies as "" not "0".