Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

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:

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


In reply to Re: Running 2 scripts at once by rjt
in thread Running 2 scripts at once by Dipseydoodle

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others imbibing at the Monastery: (9)
    As of 2015-07-08 00:35 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (93 votes), past polls