in reply to Re^2: Turning regex capture group variables into arrays, then counting the number of objects in the array
in thread Turning regex capture group variables into arrays, then counting the number of objects in the array
If you have fixed format records, then perhaps using unpack is a simpler option. For example
poj#!/usr/bin/perl use strict; use Data::Dumper ; my $fmt = 'A13 A8 A8 A10 A6 A20 A6 A12 A16 A5'; my %counts = (); my @col = ('JobID','Col2','Type','State', 'Status','Policy','Schedule','Client', 'Dest Media Svr','Active PID'); # 10 cols while (<DATA>){ next unless /\S/; # skip blank lines next if /^\s+JobID/; # skip header chomp; my @f = unpack $fmt,$_; s/^\s+|\s+$//g for @f; # trim spaces # count each column for my $n (0..$#col){ ++$counts{$col[$n]}{$f[$n]}; } print join "\|",@f,"\n"; # check } print Dumper \%counts; printf "Succesfull = %d\n",$counts{'Status'}{'0'}; __DATA__ JobID Type State Status Policy Schedule + Client Dest Media Svr Active PID 41735 Backup Done 0 Policy_name_here daily + hostname001 MediaSvr1 8100 41734 Backup Done 0 Policy_name_here daily + hostname002 MediaSvr1 7803 41733 Backup Done 0 Policy_name_here daily + hostname004 MediaSvr1 7785 41732 Backup Done 0 Policy_name_here daily + hostname005 MediaSvr1 27697 41731 Backup Done 0 Folicy_name_here daily + hostname006 MediaSvr1 27523 41730 Backup Done 0 Policy_name_here daily + hostname007 MediaSvr1 27834 41729 Backup Done 0 Policy_name_here - + hostname008 MediaSvr1 27681 41728 Backup Done 0 Policy_name_here - + hostname009 MediaSvr1 27496 41727 Catalog Backup Done 0 catalog full + hostname010 MediaSvr1 27347 41712 Catalog Backup Done 0 catalog - + hostname004 30564
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Turning regex capture group variables into arrays, then counting the number of objects in the array
by Djay (Novice) on Dec 06, 2018 at 08:54 UTC | |
by poj (Abbot) on Dec 06, 2018 at 10:25 UTC | |
by Djay (Novice) on Dec 06, 2018 at 11:20 UTC | |
by hippo (Archbishop) on Dec 06, 2018 at 12:31 UTC | |
by Djay (Novice) on Dec 06, 2018 at 13:06 UTC | |
by poj (Abbot) on Dec 06, 2018 at 12:53 UTC |