--- On Thu, 10/16/08, sanket vaidya <[EMAIL PROTECTED]> wrote: > From: sanket vaidya <[EMAIL PROTECTED]> > Subject: RE: if condition question > To: beginners@perl.org > Date: Thursday, October 16, 2008, 6:12 AM > -----Original Message----- > From: Chas. Owens [mailto:[EMAIL PROTECTED] > Sent: Thursday, October 16, 2008 2:36 PM > To: sanket vaidya > Cc: beginners@perl.org > Subject: Re: if condition question > > On Thu, Oct 16, 2008 at 04:54, sanket vaidya > <[EMAIL PROTECTED]> > wrote: > snip > > Now when I write the same if condition in program as > below, I get warning > > along with output. > snip > > $string eq "test" ? print > "correct" : ""; > snip > > Useless use of constant in void context at line 5. > snip > > >What the ternary operator* is saying is roughly > equivalant to > > >if ($string eq "test") { > print "correct" > >} else { > "" > >} > > >>That empty string by itself is what is causing the > warning. What you > really want to say is > > >>print $string eq "test" ? > "correct" : ""; > > How can I write > > if ($string eq "test") { > print "correct" > } else { > die "others" > } > > In above way?
$string eq "test" ? print "correct" : die "others"; But I don't think this is a recommended syntax. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/