perl-diddler has asked for the wisdom of the Perl Monks concerning the following question:
I have made changes over the years, but one of the things that has always bothered me is, if I want to add a complex expression -- anything that is multi-lined, how to get my input loop to know when it needs more input OR when it doesn't (vs. _could_ take more input).
My 'semi-model' for that would be something like bash, where if you type 'the beginning of a control structure, bash will change to a different prompt to indicate it wants more input.
How might I do the same in my eval/print loop?
As it is now, I can define functions on 1 line, for example, but there is no easy way to extend that to more than one line.
I could force the use of an 'extend char', like backslash at the end of line -- but in bash, those are only needed if it is ambiguous -- i.e. if the line is already well formed, you need to enter '\' to tell bash to keep parsing. Ex. (using 'home>' as normal prompt):
You can't enter partial *expressions* in bash and have it "auto continue" (that I know of). I.e.home> int a=1+1\ > +2; echo $a 4
But I could enter a '\' at the end of line and continue it as I did above.home> a=1+<cr> -bash: 1+: syntax error: operand expected (error token is "+")
Where bash works to auto-detect is in its control structures (or like if a quote is still open). Ex:
On the 2nd line, it doesn't display the normal prompt, but a single greater than sign. How could I get my input/eval loop to get feedback from perl that I'm in the middle of a similar structure and change the prompt and not try to eval it?home> for ((i=0;i<10;++i)); then<cr> > [...]
-------------
Clarification: how can I do that w/o writing an entire perl parser? ;-)
|
|---|