1 #!/usr/bin/perl -w 2 3 use strict; 4 use Text::CSV_XS; 5 my (@data,@data_epstn); 6 my ($count, $count_e_pstn) = 0; 7 my ($dothat,$dothis,$e_pstn); 8 9 ############################################################### 10 # Define attribute for STOP # 11 ############################################################### 12 my @attrs_stop = qw( _status 13 _gwname 14 _call_duration 15 _eoc_reason 16 _call_direction 17 _called_num 18 _i_pstn_trunk 19 _e_pstn_circuit); 20 21 ############################################################### 22 # Define attribute for ATTEMPT # 23 ############################################################### 24 my @attrs_attempt = qw( _status 25 _gwname 26 _eoc_reason 27 _call_direction 28 _called_num 29 _i_pstn_trunk 30 _i_pstn_circuit 31 _e_pstn_circuit 32 _e_pstn_trunk); 33 34 35 input (); 36 37 #sub stop { 38 # my @rec{@attrs_results} = @_[1,4,5]; 39 # return \%rec; 40 #} 41 42 #sub attempt { 43 # my @rec{@attrs_results} = @_[1,4,5]; 44 # return \%rec; 45 #} 46 47 ################################################################ 48 # Define sub for egress pstn # 49 ################################################################ 50 sub epstn { 51 52 } 53 ################################################################ 54 # Define sub for igress pstn # 55 ################################################################ 56 sub ipstn { 57 58 } 59 ################################################################ 60 # Define sub for extracting board info # 61 ################################################################ 62 sub extract { 63 $_ = shift; 64 #print "\$\_ is $_\n"; 65 s/^1:([0-9]|[1-9][0-9]):([0-9]|[0-9][0-9]):(?:[0-9]:[0-9][0-9][0-9]*:\S+:\S+)/$1-$2/g; 66 return $_; 67 } 68 ################################################################ 69 # Define sub for input # 70 ################################################################ 71 sub input { 72 my $csv = Text::CSV_XS->new; 73 while (<>) { 74 chomp; 75 next if /^START/; 76 $count++; 77 $csv->parse($_); 78 my @fields = $csv->fields; 79 my %rec; 80 my @attrs_results; 81 if (/^STOP/) { 82 @attrs_results = @attrs_stop; 83 # %rec = stop(@fields,@attrs_results); 84 @rec{@attrs_results} = @fields[0,1,13,14,16,20,33,36]; 85 } else { 86 @attrs_results = @attrs_attempt; 87 # %rec = attempt(@fields,@attrs_results); 88 @rec{@attrs_results} = @fields[0,1,11,13,17,30,31,33,57]; 89 } 90 push @data, \%rec; 91 } 92 } 93 ################################################################ 94 # sub ccr # 95 ################################################################ 96 sub run_ccr { 97 foreach my $results1 (@data_epstn) { 98 print "$results1->{$e_pstn}\n"; 99 } 100 } 101 ################################################################ 102 # sub short call # 103 ################################################################ 104 #sub sc ( 105 # ; 106 #} 107 ################################################################# 108 # Part of main program # 109 ################################################################# 110 foreach my $info (@data) { 111 $dothis = $info->{_status}; 112 $dothat = $info->{_call_direction}; 113 if ($dothis eq 'STOP') { 114 #print "do nothing\n"; 115 next; 116 } elsif ("$dothat" eq 'IP-TO-PSTN') { 117 my %e_pstn; 118 $count_e_pstn++; 119 my $yahoo3 = $info->{_e_pstn_circuit}; 120 my @yahoo = extract($yahoo3); 121 my $yahoo1 = $info->{_e_pstn_trunk}; 122 $e_pstn = join ":", @yahoo,$yahoo1; 123 $e_pstn{$e_pstn} = $info->{_i_eoc_reason}; 124 push @data_epstn , \%e_pstn; 125 } else { 126 ; 127 } 128 } 129 130 print " There were $count calls\n"; 131 run_ccr();