more useful options | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
Your first example could be reduced to:
As you might imagine, you don't need a Perl script to run a one-line shell command. Your second example isn't syntactically valid (unbalanced quotes), but that may have just been a copy/paste error. However, the more serious problem is that system("read $in") won't go anywhere. read(1) assigns its result to shell variables (Bash, in your case). No process (including Perl) can access shell variables from a subshell, at least not without some additional effort. There is a pure Perl way to do what you want to do (in both cases). For the second case, I suggest you look at the Perl documentation for open, print, and I/O Operators, for a basic way to open a text file for append ('>>'), accept lines of input from a user and print those lines to your text file. Finally, twice you have used this construct:
There are two problems with this. First, your condition for while, $on = "true" will always evaluate to TRUE. This is because you are assigning the value "true" to the variable $on every time through the loop, and the assignment operator returns the value assigned. Since you are comparing strings, you would want to use $on eq 'true' to do what you want, which is compare the value of $on to the string 'true'. (If you were comparing numbers, you would use == instead of eq). Second, you actually don't need this clumsy construct and extra variable at all. You could equivalently write: while (1) { ... }Or, probably, once you get the hang of <>, something like below, but don't highlight the text below if you want to figure this out on your own: <Reveal this spoiler or all in this thread>
Keep at it, though. It gets logarithmically easier the more you learn. :-) In reply to Re: Running 2 scripts at once
by rjt
|
|