in reply to Parsing output with a special format

Part 2 is pretty easy so here's one approach.

#!/usr/bin/env perl use strict; use warnings; my %status; while (<DATA>) { next unless /@/; my @fields = split; $status{$fields[1]} = $fields[0]; } use Data::Dumper; print Dumper (\%status); __DATA__ date:17/4/2000 version: 4.1.0 -more info- -more info- ------------------------------------------------------------------ Status id not important info (two columns) name ----------------------------------------------------------------- Run 1234 @ ... foo1 Wait 54123 @ ... foo2 -----------------------------------------------------------------

This should give you enough to work on regarding point 1.

Replies are listed 'Best First'.
Re^2: Parsing output with a special format
by ovedpo15 (Pilgrim) on Jun 05, 2018 at 08:42 UTC
    I use the `system` commend.
    my $test_output = system($cmd);
    how can I iterate over it like you did with DATA.
    maybe I should use: my @test_output = system($cmd);?
      my $test_output = system($cmd);

      That won't work, since system returns the exit code and does not capture the command's output. I would recommend capture or capturex from IPC::System::Simple, which can give you an array of lines (my @lines = capture($cmd);). Otherwise, e.g. if the command's output is too large to be captured all at once, you could use a piped open, as I showed here along with other possible solutions.