abhijithtk has asked for the wisdom of the Perl Monks concerning the following question:
Hello All..
I just have a couple of questions and will be glad to read your responses. Detailed explanations of what exactly is happening/going on will be appreciated.
Il post a simple piece of code and then the question.#!/usr/bin/perl use strict; use warnings; my $x = 'ls -l'; open(OP,"$x |"); while(<OP>) { print; } close OP;
Another way to execute a command is using backticks.
$x = `ls -l`;
When we use the open method to execute a command(assuming the command produces a lot of data), apparently since the output is read line by line less memory is used up. (As opposed to reading the entire output into a scalar while using backticks).
My question is how are these 2 methods different.
Since even when we use the open method, isnt the entire output being stored somewhere and then being fetched to be printed out line by line?? If thats the case dont they use up the same amount of memory?
Can anyone explain?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Executing Commands with "open"
by ikegami (Patriarch) on Jun 14, 2010 at 15:56 UTC | |
by abhijithtk (Novice) on Jun 14, 2010 at 16:11 UTC | |
by JavaFan (Canon) on Jun 14, 2010 at 16:22 UTC | |
by ikegami (Patriarch) on Jun 14, 2010 at 16:56 UTC | |
by BrowserUk (Patriarch) on Jun 14, 2010 at 18:29 UTC | |
by ikegami (Patriarch) on Jun 14, 2010 at 19:06 UTC | |
by abhijithtk (Novice) on Jun 14, 2010 at 18:40 UTC | |
|
Re: Executing Commands with "open"
by cdarke (Prior) on Jun 14, 2010 at 17:37 UTC |