in reply to Making program readable
I have no way of testing this proposal in a relevant way, but I think the layout is basically in line with what you're trying to do. (Note that I'm renaming your "$AO_ESMEdep_error" to a hash key spelled "AO_userdep_error", to maintain parallelism between the GSM and SMPP conditions - I hope that doesn't warp things too much for you (the parallelism is worth it, I think).
I also altered the handling of open failures and shortened the variable names.my %tallies; my %errors = { userdep_error => \@subscriber_error, network_error => \@network_error, system_error => \@system_error, }; sub do_GSM { my $fields = shift; if ( $$fields[9] eq 'MSubmit' ) { $tallies{MO_count}++; if ( $$fields[7] eq 'MsgAccepted' ) { $tallies{MO_success]++; } } if ( $$fields[13] eq 'SMPP' ) { $tallies{AT}++; } for my $type ( keys %errors ) { if ( any { /^\Q$$fields[11]\E$/ } @{$errors{$type}} ) { $tallies{"MO_$type"}++; } } } sub do_SMPP { my $fields = shift; if ( $$fields[9] eq 'ESubmit' ) { $$tallies{AO_count}++; if ( $$fields[7] eq 'MsgAccepted' ) { $tallies{AO_success}++; } } if ( $$fields[11] =~ /SMSC/ ) { for my $type ( keys %errors ) { if ( any { /^\Q$$fields[11]\E$/ } @{$errors{$type}} ) { $tallies{"AO_$type"}++; } } } } my %subs = ( GSM => \&do_GSM, SMPP => \&do_SMPP ); foreach my $Intermediate_file (@Intermediate_files) { unless ( open (INTER, $Intermediate_file )) { warn "open failed for $Intermediate_file\n"; next; } while (<INTER>) { chomp; my @fields = split(/\|/); &{$subs{$fields[12]}}( \@fields ); } } print "Completed the Imtermediate section....\n"; ...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Making program readable
by ravi45722 (Pilgrim) on Oct 07, 2015 at 04:28 UTC |