http://www.perlmonks.org?node_id=1067306

simonz has asked for the wisdom of the Perl Monks concerning the following question:

Hi,
I am getting a warning while executing the following code in case where I am not using any variable for the ternary operator. Why I am getting warning like "Useless use of a constant in void context at a.pl" for not using the variable ? How can I write the code without using the variable and not getting the warning as well.

my $hash = {}; my $i = "one"; #Below line giving no warning. But I DO NOT want this #my $val = ($i eq 'one') ? $hash->{'name'} = "hello"."world" : 'nothin +g'; # Below line giving warning. But I want this ($i eq 'one') ? $hash->{'name'} = "hello"."world" : 'nothing';