convenientstore has asked for the wisdom of the Perl Monks concerning the following question:
example of output from aboveuse strict; use diagnostics; use Text::CSV_XS; use Data::Dumper; my ($counter,$ncounter); my (@data , @data1); my @attrs_sto = qw( _status _gwname _acct_id _call_duration _eoc_reason _call_direction _called_num _i_pstn_trunk _i_pstn_circuit _e_pstn_circuit _e_pstn_trunk ); my @attrs_att = qw( _status _gwname _acct_id _eoc_reason _call_direction _called_num _i_pstn_trunk _i_pstn_circuit _e_pstn_circuit _e_pstn_trunk ); my @attrs_sta = qw( _status _gwname _acct_id _call_direction _called_num _i_pstn_trunk _i_pstn_circuit _e_pstn_circuit _e_pstn_trunk ); @ARGV = ('./sonuslog') unless @ARGV; my $csv = Text::CSV_XS->new; while (<>) { chomp; $csv->parse($_); my @fields = $csv->fields; my %rec; if (/^STOP/) { @rec{@attrs_sto} = @fields[0,1,2,13,14,16,20,33,34,36,67 +]; } elsif (/^START/) { @rec{@attrs_sta} = @fields[0,1,2,11,15,28,29,31,53]; } else { @rec{@attrs_att} = @fields[0,1,2,11,13,17,30,31,33,57]; } push @data, \%rec; } my %ipstn; foreach (@data) { my %ipstn_s; my %ipstn_a; $counter++; if ($_->{_status} eq 'STOP') { next ; } else { if ($_->{_status} eq 'START' && $_->{_i_pstn_trunk}) { my $i_pstn_si = extract($_->{_i_pstn_circuit}, $_->{_i_p +stn_trunk}); push @{$ipstn_s{$i_pstn_si}}, $_; pushnow(\%ipstn_s); } else { if ($_->{_status} eq 'START') { my $e_pstn_se = extract($_->{_e_pstn_circuit}, $_->{ +_e_pstn_trunk}); push @{$ipstn_s{$e_pstn_se}}, $_; pushnow(\%ipstn_s); } else { if ($_->{_status} eq 'ATTEMPT' && $_->{_i_pstn_trunk} +) { my $i_pstn_ai = extract($_->{_i_pstn_circuit}, $_- +>{_i_pstn_trunk}); push @{$ipstn_a{$i_pstn_ai}}, $_; pushnow(\%ipstn_a); } else { if ($_->{_status} eq 'ATTEMPT') { my $e_pstn_ae = extract($_->{_e_pstn_circuit}, +$_->{_e_pstn_trunk}); push @{$ipstn_a{$e_pstn_ae}}, $_; pushnow(\%ipstn_a); } else { $ncounter++; } } } } } } print Dumper(@data1); sub pushnow { push @data1, @_; } sub extract { return join('-', (split(/:/, $_[0]))[1,2], $_[1]); }
$VAR14029 = { '11-57-USNxxxxxxxxxx' => [ { '_acct_id' => '0xxxxxxxxxx +xxxxxx', '_i_pstn_trunk' => '', '_called_num' => '5551213' +, '_status' => 'START', '_gwname' => 'xxxxxxxxxxxx +', '_i_pstn_circuit' => '', '_e_pstn_circuit' => '1:11 +:57:8:0:0x00000000:0x00000000', '_e_pstn_trunk' => 'USNxxx +xxxxxxxxx', '_call_direction' => 'IP-T +O-PSTN' } ] }; $VAR14030 = { '10-12-USNxxxxxxxx_D' => [ { '_acct_id' => '0xxxxxxxxxxx +xxxxxxxxx', '_i_pstn_trunk' => 'USNxxxx +xxxx_D', '_called_num' => '5551212', '_status' => 'START', '_gwname' => 'xxxxxxxxxxx', '_i_pstn_circuit' => '1:10: +12:22:8350:0x0001F8F0:0x00056940', '_e_pstn_circuit' => '', '_e_pstn_trunk' => '', '_call_direction' => 'PSTN- +TO-IP' } ] };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: help on my overall program
by GrandFather (Saint) on Oct 15, 2007 at 03:40 UTC |