I am currently having a very simple problem with capturing the output from a backticked shell command. I apologize that the problem is rather simple.
I have some sorted array (@valid_runs) which I know contains consecutive, duplicate elements. I want to use backticks to echo this array to uniq. I want to capture the STDOUT in an array. I attempt to do so like this.
@unique_valids = `echo '@valid_runs' | uniq`;
print @unique_valids;
This print statement yields nothing. For that matter neither does this.
@unique_valids = `echo '@valid_runs'`;
print @unique_valids;
I know how to use uniq and echo. This seems rather odd to me. I would think this has more to do with perl arrays than proper use of those commands. I have searched around a bit elsewhere, so please don't pelt me with downvotes just because the solution might seem trivial. Thanks again for your time.
NOTE on solutions: TLP's solution is the most straightforward as far handling the uniq problem. I am being rather flexible, since all responses suggested not making a system call for this problem. If Perl's uniq function the same as Unix's uniq then the array ought to remain sorted.
John Corbett's solution works well if you don't care about a sorted result.
@valid_runs
end in a newline? otherwiseecho
will only produce one line of output as input touniq
– Nalda@valid_runs
is not empty? this prints something for me:@x=(3,2,1);@y = `echo '@x'`;print @y;
– Nalda/raid1/home/pharmacy/morguna/1experiments_copy/1experiments/test10-10/run36415 /raid1/home/pharmacy/morguna/1experiments_copy/1experiments/test10-10/run36415 /raid1/home/pharmacy/morguna/1experiments_copy/1experiments/test10-10/run36416 /raid1/home/pharmacy/morguna/1experiments_copy/1experiments/test10-10/run36416
– Plastid