I have to access a shell command - hive within a Perl script, So I use `...`. Assuming the result of `hive ... ...` contains 100000000 lines and is 20GB size. what I want to achieve is like this:
@array = `hive ... ...`;
Does `` automatically know to use "\n" as separator to divide each line into the @array?
The 2 ways I can thought of are (but with problem in this case):
$temp = `hive ... ...`;
@array = split ( "\n", $temp );
undef $temp;
The problem of this way is that if the output of hive is too big in this case, the $temp cant store the output, resulting in segmentation fault core dump.
OR
`hive ... ... 1>temp.txt`;
open ( FP, <, "temp.txt" );
while (<FP>)
{
chomp;
push @array, $_;
}
close FP;
`rm temp.txt`;
But this way would be too slow, because it writes result first to hard-disk.
Is there a way to write the output of a shell command directly to an array without using any 'temporary container'?
Very Thanks for helping.