in reply to Re: Re: If / elses
in thread If / elses
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";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: (tye)Re: If / elses
by jeroenes (Priest) on Mar 13, 2001 at 17:38 UTC | |
by tye (Sage) on Mar 13, 2001 at 19:59 UTC |