LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Perl: Condition?print "Is true":print "Is false"; (http://www.linuxquestions.org/questions/programming-9/perl-condition-print-is-true-print-is-false-%3B-832756/)

angel115 09-17-2010 03:48 AM

Perl: Condition?print "Is true":print "Is false";
 
Hello There,

I was wondering if perl got the equivalent of php for the coditional check below:
Code:

Condition?print "true":print "false";

Ex:
isset($_)?print "$_":print "\$_ is not set";

When I try to use it it give my the following error:
syntax error at ./shutdown_all line 33, near ")?"

tshikose 09-17-2010 06:21 AM

Hi angel115,

Try the below in Perl.

print defined($_)? "$_": "\$_ is not defined";

Regards,

Tshimanga.

angel115 09-17-2010 07:28 AM

It's working, Thanks.


All times are GMT -5. The time now is 04:00 AM.