Reading output from command into Perl array -
i want output of command array — this:
my @output = `$cmd`; but seems output command not go @output array.
any idea go?
this simple script works me:
#!/usr/bin/env perl use strict; use warnings; $cmd = "ls"; @output = `$cmd`; chomp @output; foreach $line (@output) { print "<<$line>>\n"; } it produced output (except triple dots):
$ perl xx.pl <<args>> <<args.c>> <<args.dsym>> <<atob.c>> <<bp.pl>> ... <<schwartz.pl>> <<timer.c>> <<timer.h>> <<utf8reader.c>> <<xx.pl>> $ the output of command split on line boundaries (by default, in list context). chomp deletes newlines in array elements.
Comments
Post a Comment