in reply to Re: Main logic of this script (summary/abstract/outline)
in thread Main logic of this script

Here is my version, 1145 lines reduced to 208 comments
# if($opt_h) # if($opt_O) # if($opt_O =~ /^connection$|^conn$|^c$/i) # elsif ($opt_O =~ /^operation$|^op$|^o$/i) # elsif ($opt_O =~ /^sort$|^so$/i) # elsif ($opt_O =~ /^statistics$|^statistic$|^stats$|^ +stat$|^st$/i) # elsif ($opt_O =~ /^e|^echo$/i) # else # else # if($opt_S =~ /^(\d+)\/([A-Za-z]+)\/(\d+)\:(\d+):(\d+):(\d+)$/) # elsif ($opt_S =~ /^(\d+):(\d+):(\d+)$/) # else # if($opt_S) # if($opt_E =~ /^(\d+)\/([A-Za-z]+)\/(\d+)\:(\d+):(\d+):(\d+)$/) # elsif ($opt_E =~ /^(\d+):(\d+):(\d+)$/) # else # if($opt_E) # if($opt_S) # if($lower_yr) # if($opt_E) # if($upper_yr) # if($output_format =~ /^connection$|^operation$/) # unless($ARGV[0]) # if($ARGV[1]) # else # elsif ($output_format =~ /^sort$|^echo$|^stat$/) # if($ARGV[0]) # else # if($output_format eq 'operation') # while(<ACCESS_LOG>) # unless($log_line =~ /^\[(\d+)\/([A-Za-z]+)\/(\d+ +)\:(\d+):(\d+):(\d+) ([+|-]\d+)\] conn\=([-]*\d+) op\=([-]*\d+) msgId +\=([-]*\d+) \- (.+)$/) # "next;" # if($opt_S) # unless($lower_epoch) # if($opt_E) # unless($upper_epoch) # if((($opt_S) && ($current_epoch < $lower_epoch)) + || (($opt_E) && ($current_epoch > $upper_epoch))) # "next;" # if(($op_number eq '-1') || ($msgid_number eq '-1 +')) # else # if(($operation_key eq '0:INTERNAL') && ($log_pay +load =~ /connection from/)) # if($opt_v) # foreach(keys(%pending)) # if(($log_payload =~ /^RESULT |^closed\.$|^UNBIND +$|^ABANDON /)) # if(@skipping) # foreach(0..$#skipping) # if($skipping[$i] eq $operation_k +ey) # if($this_is_a_result) # "last;" # if(@printing) # foreach(0..$#printing) # if($printing[$i] eq $operation_k +ey) # if($this_is_a_result) # "last;" # if($this_is_printing) # "next;" # if($skip_this) # "next;" # if(%pending) # if(exists($pending{$operation_key})) # if($opt_v) # if($opt_i) # if($log_line !~ /$filt_expr/i) # else # if($log_line !~ /$filt_expr/) # else # if($opt_i) # if($log_line =~ /$filt_expr/i) # else # if($log_line =~ /$filt_expr/) # if($this_is_a_match) # if($opt_v) # if(($this_is_a_result) && ($this +_is_pending)) # elsif ($this_is_a_result) # else # if($this_is_pending) # else # else # unless($this_is_a_result) # if($this_is_pending) # else # if($opt_v) # unless($this_is_a_result) # if($this_is_pending) # else # if(($this_is_a_result) && ($this +_is_pending)) # elsif ($this_is_pending) # else # if($opt_v) # foreach(keys(%pending)) # if($output_format eq 'connection') # while(<ACCESS_LOG>) # unless($log_line =~ /^\[(\d+)\/([A-Za-z]+)\/(\d+ +)\:(\d+):(\d+):(\d+) ([+|-]\d+)\] conn\=([-]*\d+) op\=([-]*\d+) msgId +\=([-]*\d+) \- (.+)$/) # "next;" # if($opt_S) # unless($lower_epoch) # if($opt_E) # unless($upper_epoch) # if((($opt_S) && ($current_epoch < $lower_epoch)) + || (($opt_E) && ($current_epoch > $upper_epoch))) # "next;" # if(($connection_key eq '0') && ($log_payload =~ +/connection from/)) # if($opt_v) # foreach(keys(%pending)) # if(($op_number eq '-1') && ($msgid_number eq '-1 +') && ($log_payload eq 'closed.')) # if(@skipping) # foreach(0..$#skipping) # if($skipping[$i] eq $connection_ +key) # "last;" # if(@printing) # foreach(0..$#printing) # if($printing[$i] eq $connection_ +key) # if($this_is_a_close) # "last;" # if($this_is_printing) # "next;" # if($skip_this) # "next;" # if(%pending) # if(exists($pending{$connection_key})) # if($opt_v) # if($opt_i) # if($log_line !~ /$filt_expr/i) # else # if($log_line !~ /$filt_expr/) # else # if($opt_i) # if($log_line =~ /$filt_expr/i) # else # if($log_line =~ /$filt_expr/) # if($this_is_a_match) # if($opt_v) # if(($this_is_a_close) && ($this_ +is_pending)) # elsif ($this_is_a_close) # else # if($this_is_pending) # else # else # unless($this_is_a_close) # if($this_is_pending) # else # if($opt_v) # unless($this_is_a_close) # if($this_is_pending) # else # if(($this_is_a_close) && ($this_ +is_pending)) # elsif ($this_is_pending) # else # if($opt_v) # foreach(keys(%pending)) # if($output_format eq 'sort') # while(<ACCESS_LOG>) # unless($log_line =~ /^\[(\d+)\/([A-Za-z]+)\/(\d+ +)\:(\d+):(\d+):(\d+) ([+|-]\d+)\] conn\=([-]*\d+) op\=([-]*\d+) msgId +\=([-]*\d+) \- (.+)$/) # "next;" # if($opt_S) # unless($lower_epoch) # if($opt_E) # unless($upper_epoch) # if((($opt_S) && ($current_epoch < $lower_epoch)) + || (($opt_E) && ($current_epoch > $upper_epoch))) # "next;" # if(($log_payload =~ /connection from/) && ($op_n +umber eq '-1') && ($msgid_number eq '-1')) # elsif (($msgid_number eq '-1') && ($log_payl +oad =~ /closing/)) # elsif (($op_number eq '-1') && ($msgid_numbe +r eq '-1') && ($log_payload eq 'closed.')) # elsif (($op_number eq '-1') || ($msgid_numbe +r eq '-1')) # else # if(($log_payload =~ /^RESULT /)) # if(($this_is_an_open) && ((exists($connections{$ +connection_key})) || ($connection_key eq '0'))) # foreach(@conn_nums) # foreach(@conn_nums) # if($output_format eq 'stat') # while(<ACCESS_LOG>) # unless($log_line =~ /^\[(\d+)\/([A-Za-z]+)\/(\d+ +)\:(\d+):(\d+):(\d+) ([+|-]\d+)\] conn\=([-]*\d+) op\=([-]*\d+) msgId +\=([-]*\d+) \- (.+)$/) # "next;" # if($opt_S) # unless($lower_epoch) # if($opt_E) # unless($upper_epoch) # if((($opt_S) && ($current_epoch < $lower_epoch)) + || (($opt_E) && ($current_epoch > $upper_epoch))) # "next;" # unless($start_epoch) # if($current_epoch > $end_epoch) # if($result_count > 0) # else # if(($log_payload =~ /^RESULT (.+) nentries=(\d+) + etime=(.+?) (.+)$/) || ($log_payload =~ /^RESULT (.+) nentries=(\d+) + etime=(.+?)$/)) # if($3 > $etime_max) # if($4 =~ /notes\=U/) # elsif ($log_payload =~ /^closed\.$/) # elsif ($log_payload =~ /connection from /) # elsif ($log_payload =~ /^ADD /) # elsif ($log_payload =~ /^MOD /) # elsif ($log_payload =~ /^DEL /) # elsif ($log_payload =~ /^SRCH /) # elsif ($log_payload =~ /^BIND /) # elsif ($log_payload =~ /^EXT /) # else # unless($log_payload =~ /^UNBIND$|^ABANDO +N |closing/) # if($result_count > 0) # else # if($output_format eq 'echo') # while(<ACCESS_LOG>) # unless($log_line =~ /^\[(\d+)\/([A-Za-z]+)\/(\d+ +)\:(\d+):(\d+):(\d+) ([+|-]\d+)\] conn\=([-]*\d+) op\=([-]*\d+) msgId +\=([-]*\d+) \- (.+)$/) # "next;" # if($opt_S) # unless($lower_epoch) # if($opt_E) # unless($upper_epoch) # if((($opt_S) && ($current_epoch < $lower_epoch)) + || (($opt_E) && ($current_epoch > $upper_epoch))) # "next;" # if($in_file)

This manual outline generation wouldn't be necessary if the original was skimmable code :)

Replies are listed 'Best First'.
Re^3: Main logic of this script (summary/abstract/outline)
by Anonymous Monk on Mar 09, 2015 at 09:27 UTC
    from 208 to 28 and 18

    options var init stuff

    meat and potatoes (read the log)

      So the skimmable version might have been (or the new refactored version might be)

      #!/usr/bin/perl -- Main( @ARGV ); exit( 0 ); sub Main { use Getopt::Long; my %opt; GetOptions( \%opt, ... ); my %needed = ValidateOptionsAndInitializeStuffWeNeed( \%opt ); return PrintHelp() if $opt{help_needs_to_happen}; return ReadTheLogBasedOnFormat( \%opt , \%needed ); } sub ValidateOptionsAndInitializeStuffWeNeed { my( $optref ) = @); ... if( ... ){ die "Unknown output type ..."; } ... }