in reply to Splitting output of a system command into an array

You seem to have the method correct: use backticks (see perlop) to capture the output of free into a scalar. Then split on whitespace to get the "words":
my $free = `free`; my @words = split /\s+/, $free; shift @words if $words[0] eq '';

shift removes an empty string from @words caused by $free starting with spaces.

Replies are listed 'Best First'.
Re^2: Splitting output of a system command into an array
by jwkrahn (Abbot) on Sep 29, 2007 at 20:50 UTC
    my @words = split /\s+/, $free;
    shift removes an empty string from @words caused by $free starting with spaces.

    Or you could just use split correctly and you wouldn't have an empty string.

    my @words = split ' ', $free;
Re^2: Splitting output of a system command into an array
by sKiBa (Initiate) on Sep 29, 2007 at 17:58 UTC
    That's exactly what I was after, thank you. I will have to read through all my various test scripts as i'm sure I had tried that, definitely hadn't done the shift though. Also, is it possible to read each line into it's own array rather than all into one?
      Also, is it possible to read each line into it's own array rather than all into one?
      Yes, just use my @lines = `free`;