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?In reply to Executing Commands with "open" by abhijithtk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |