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';
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Warning while using ternary operator
by BrowserUk (Patriarch) on Dec 16, 2013 at 10:53 UTC | |
by simonz (Sexton) on Dec 16, 2013 at 11:10 UTC | |
by BrowserUk (Patriarch) on Dec 16, 2013 at 11:14 UTC | |
by Athanasius (Archbishop) on Dec 16, 2013 at 12:49 UTC | |
by Bloodnok (Vicar) on Dec 16, 2013 at 14:45 UTC | |
|
Re: Warning while using ternary operator
by Anonymous Monk on Dec 16, 2013 at 13:42 UTC | |
by kcott (Archbishop) on Dec 16, 2013 at 15:19 UTC | |
by AnomalousMonk (Archbishop) on Dec 16, 2013 at 23:15 UTC | |
|
Re: Warning while using ternary operator
by mward (Initiate) on Dec 17, 2013 at 11:46 UTC | |
by tobyink (Canon) on Dec 17, 2013 at 11:51 UTC |