Why does Perl's string multiplication not warn on undef?


use strict;
use warnings;
my $foo = undef;

the expressions

$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.


I once saw a show with a scene in a law school class. The instructor presented two similar cases to his students and asked why did they result in different rulings. It's because the rulings were made by judges, and judges are people, he eventually explained.

That should warn. The developers that work on Perl are people. Run perlbug to send a bug report if you wish.

Need Your Help

How to use Scanner to accept only valid int as input

java validation java.util.scanner

I'm trying to make a small program more robust and I need some help with that.

How to convert string to XML object in JavaScript?

javascript jquery xml

I am aware of this question already existing, but it has given me no luck.