in reply to Redirecting OUTPUT of system($command) to an array

my $command="/usr/local/coms/command "; my @array = `$command`;

Backticks are what you're looking for.

Replies are listed 'Best First'.
Re: Re: Redirecting OUTPUT of system($command) to an array
by Limbic~Region (Chancellor) on May 13, 2004 at 18:30 UTC
    Nkuvu,
    I would guess that this is 1 step short of being what is desired ultimately. The output likely needs to be split (by either horizontal or vertical whitespace).
    my $command = "/usr/local/some/command"; my $result = `$command`; my @array = split /\n/ , $result;
    Otherwise the entire result ends up in slot 0 of the array you will have no control over how the output is stored into the array.

    Cheers - L~R

    Update: If the desired outcome is to split on newlines, then there is no need to store the result into a temporary scalar and split yourself as japhy points out below.
      Except that readpipe() (which is what implements `...` and qx()) returns a list of lines in list context. So an array on the left-hand side is fine.
      _____________________________________________________
      Jeff[japhy]Pinyan: Perl, regex, and perl hacker, who'd like a job (NYC-area)
      s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

      Thanks for the caveat, I'll keep that in mind. So far, every time I've resorted to using backticks, the system command I've been executing has output multiple lines of information.