in reply to Parsing output from a 'system' call into objects?

Very similar to anonymonk's post, but without the module (just got sidetracked before I could post the solution):

use warnings; use strict; use Data::Dumper; my @lines = split /\n/, `cat data.txt`; my %out; for (@lines){ next if /CoID:/; my ($co, $type, $state, $id) = split; next if ! $id; next if $type ne 'A'; $out{$id}->{CoID} = $co; $out{$id}->{State} = $state; } print Dumper \%out;

Replies are listed 'Best First'.
Re^2: Parsing output from a 'system' call into objects?
by choroba (Cardinal) on Feb 22, 2017 at 04:04 UTC
    my @lines = split /\n/, `cat data.txt`;

    can be replaced by

    chomp( my @lines = `cat data.txt` );

    It only makes sense to commands different to cat , of course, otherwise you'd just

    open my $IN, '<', 'data.txt' or die $!; chomp( my @lines = <$IN> );

    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
Re^2: Parsing output from a 'system' call into objects?
by huck (Prior) on Feb 21, 2017 at 20:34 UTC

    any comment on why you skipped the type eq 'A' requirement?

      Because I overlooked it. Added the single line to correct the oversight.