Under
use strict;
use warnings;
my $foo = undef;
the expressions
$foo . ''
and
"$foo"
both produce
Use of uninitialized value $foo in ... at ...
but the following expression gives the empty string without warning:
$foo x 1
Anyone knows why? I mean, it's cool to have a nice stringification idiom ($_ x 1
is quite much shorter than defined ? "$_" : ''
), but it feels a bit weird.
perldoc perlop
(search for "Multiplicative Operators") doesn't say anything about the behavior ofx
with anundef
left operand. I agree it's probably unintentional. – Pillbox