Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Running 2 scripts at once

by rjt (Deacon)
on Nov 14, 2012 at 01:11 UTC ( #1003728=note: print w/ replies, xml ) Need Help??


in reply to Running 2 scripts at once

Your first example could be reduced to:

#!/usr/bin/perl system('tail -F chatlog.txt');

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:

$on = "true"; while ($on = "true") { ... }

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:

while (<>) { print $fh $_; }

Keep at it, though. It gets logarithmically easier the more you learn. :-)


Comment on Re: Running 2 scripts at once
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1003728]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (7)
As of 2014-08-31 09:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (294 votes), past polls