Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
Compound statements within the conditional (ternary) operatorby Fendo (Novice) |
on Apr 14, 2018 at 12:04 UTC ( [id://1212866]=perlquestion: print w/replies, xml ) | Need Help?? |
Fendo has asked for the wisdom of the Perl Monks concerning the following question:
Hello wise monks! I come to ask for your kind advice and enlightenment on the following matter:
I've been trying to print a character a certain number of times, if a certain condition is met. For the printing, I use an “until” loop. For the condition, I would like to use the conditional (ternary) operator. However, this apparently results in a syntax error. Below is example code which produces the error. My intention was to print the equals sign ten times instead.
This results in the error: syntax error at ./example.pl line 8, near ""=" until". I have tried using a different form for the loop:
However, that results in a similar error: syntax error at ./example.pl line 8, near "( until". When I try to achieve this using “if” and “else”, it works very well, using this code: Is it possible to use such constructions within the conditional (ternary) operator, as I've been trying to do? And if yes, how may I do so correctly? Thank you in advance!
Back to
Seekers of Perl Wisdom
|
|