Great answer.
For some reason, I expect that several people will be tempted to transform this into:
print ( $foo == 1 ) ? "hi" : "bye";and I just wanted to note that doing so will break it, printing either "1" or "" and then returning the value of "hi" to the "void context" unless the print failed. (But if you have warnings enabled, you will get a warning for the above code.)
Two ways to fix this are:
- tye (but my friends call me "Tye")print( ( $foo == 1 ) ? "hi" : "bye" ); print +( $foo == 1 ) ? "hi" : "bye";
In reply to (tye)Re: If / elses
by tye
in thread If / elses
by mbond
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |