in reply to Re: Read System output Into a variable Name?
in thread Read System output Into a variable Name?

using open() is a quick easy way of doing it. But working with external files slows down any script. I would suggest using backticks, and then parsing out the data you want using regex and/or split. I had a script which was taking 15 minutes to run when it was using external files. I optimized it using split -- and now it only takes 8 minutes. But as the perl slogan goes: There is more than one way to do it.

- Justin
  • Comment on Re^2: Read System output Into a variable Name?

Replies are listed 'Best First'.
Re^3: Read System output Into a variable Name?
by dragonchild (Archbishop) on Feb 02, 2005 at 01:44 UTC
    I'm not quite sure I understand where you're going here. The use of backticks is essentially a wrapper around open("-|"). The only difference is that you're using the OS to buffer your data as opposed to pulling it all into your process memory. If the output from the external process is large, you can easily start paging your process's memory. If you treat it as a socket (which, in essence, it is), you can bring the results in as you need, keeping only the data you want.

    Unless, of course, you thought I was using system(), redirecting the results to a temp file, then open()'ing the temp file ... that's not what I was suggesting. Please read the documentation for open and look for the section dealing with -|.

    Being right, does not endow the right to be rude; politeness costs nothing.
    Being unknowing, is not the same as being stupid.
    Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
    Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.