in reply to Making program readable

I'd be inclined to maximize the use of distinct subroutines for specific subsets of data, as well as using more hashes to organize things according to types and labels. Here's how I would try to structure the first part of the OP code. (I think the array idea mentioned above will help a lot with the rest.)

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).

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"; ...
I also altered the handling of open failures and shortened the variable names.

Replies are listed 'Best First'.
Re^2: Making program readable
by ravi45722 (Pilgrim) on Oct 07, 2015 at 04:28 UTC

    Thank you very much for trying to simplify my code. But I think you aware of GSM & SMPP differences. In GSM (Person to person) there is user_errors. In SMPP (Application to person) there is ESME_errors. We cannot club them. It's totally different. Thanks once again for reply.