sanket vaidya wrote:
Hi all,

Hello,

Kindly go through the below codes:

use warnings;
use strict;
my $string = "test";
if ($string eq "test")
{
print "correct";
}

Output:
Correct

Now when I write the same if condition in program as below, I get warning
along with output.

use warnings;
use strict;
my $string = "test";
$string eq "test" ? print "correct" : "";

Output:
Correct
Useless use of constant in void context at line 5.

Can any one suggest the reason of warning in Case2.

Your second example is equivalent to:

if ( $string eq "test" ) {
    print "correct";
    }
else {
    "";
    }

Where the string "" is in void context.


It is correctly written as:

print $string eq "test" ? "correct" : "";




John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to