#!/usr/bin/perl #use strict; #use warnings; use Getopt::Long; GetOptions(\%option, "filename=s"); die("Usage: analyse_sql.perl -filename=\n") unless $option{'filename'}; # Format of the output file: format STDOUT_HEAD = @<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<< $run_title, $table_ar[0], $table_ar[1], $table_ar[2], $table_ar[3], $table_ar[4], $table_ar[5], $table_ar[6], $table_ar[7], $table_ar[8], $table_ar[9] . format STDOUT_BODY = @<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<< $cur_run, $out_row_ar[0], $out_row_ar[1], $out_row_ar[2], $out_row_ar[3], $out_row_ar[4], $out_row_ar[5], $out_row_ar[6], $out_row_ar[7], $out_row_ar[8], $out_row_ar[9] . #format = #^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ~~ #$_ #. @out_row_ar; $run_title; $cur_run; @table_ar; $table_ar_size=0; @tmp_table_res_ar; $tmp_table_res_ar_size=0; @results_ar; $results_ar_size=0; $results_ar_row; @results_run_ar; $results_run_ar_size=0; $flag=0; $therun=0; $found =0; $foundpos =0; $thetable; $thecid; # Read in table list: open(SOURCE,"cat $option{'filename'} |"); while(){ chomp; @table_ar[$table_ar_size] = $_; $table_ar_size++; }#while ##test table ar: #print STDOUT "Tables:\n"; #for($i=0; $i<$table_ar_size; $i++){ # print STDOUT "$table_ar[$i]\n"; #}#for # tmp table results array init: $tmp_table_res_ar_size=$table_ar_size; for($j=0; $j<$tmp_table_res_ar_size; $j++){ $tmp_table_res_ar[$j] = 0; }#for # Now parse the sql output file and store full results in @results_ar open(SOURCE2,"cat get_cid_tables.txt |"); while(){ chomp; if(/Run\:/){ split; $therun = @_[1]; }#if #################### # START MAIN ANALYSIS BLOCK #################### if(/ENDPERL/){ $flag=0; # Now the tmp_table_res_ar is full, output it to the main results arrays # First the run $results_run_ar[$results_run_ar_size] = $therun; $results_run_ar_size++; # now the CID combination $results_ar_row = $tmp_table_res_ar[0]; for($k=1; $k<$tmp_table_res_ar_size; $k++){ $results_ar_row = $results_ar_row . " "; $results_ar_row = $results_ar_row . $tmp_table_res_ar[$k]; }#for #put it in the array: $results_ar[$results_ar_size] = $results_ar_row; $results_ar_size++; }#if if($flag == 1){ # We are in the table list. split; $thetable=@_[1]; $thecid=@_[0]; #print STDOUT "table outer: $thetable\n"; # Look for this table in the tablelist: $found=0; for($i=0; $i<$table_ar_size; $i++){ #print STDOUT "considering $thetable and $table_ar[$i]\n"; if($table_ar[$i] eq $thetable){ #print STDOUT "IN!\n"; $found=1; $foundpos = $i; }#if }#for if($found==1){ # This table is on the analysis list. # Put its cid in the table position in the tmp results array. #print STDOUT "table: $table_ar[$foundpos] cid: $thecid foundpos: $foundpos\n"; $tmp_table_res_ar[$foundpos] = $thecid; }#if }#if if(/STARTPERL/){ $flag=1; }#if #################### # END MAIN ANALYSIS BLOCK #################### }#while # Test output of the results array: #print STDOUT "Results array:\n"; #for($l=0; $l<$results_ar_size; $l++){ # print STDOUT "$results_run_ar[$l] : $results_ar[$l]\n"; #}#for # Iterate over results array and only print the first run, and any runs where any of the cid's change. print STDOUT "=================================================\n"; print STDOUT "Results (not including runs where no cids changed)\n"; print STDOUT "Format is Run in left column, then cids for tables\n"; print STDOUT "in the columns under the respective table names\n"; print STDOUT "=================================================\n"; print STDOUT "\n\n"; # Print table headings: $run_title='Run: '; $~ = STDOUT_HEAD; write; #print STDOUT "\n\n\n"; # Change to body format. $~ = STDOUT_BODY; # Print first result: $cur_run = $results_run_ar[0]; $_ = $results_ar[0]; @out_row_ar = split; write; # Print the rest (missing out the ones where nothing changes) $results_ar_row = $results_ar[0]; for($l=1; $l<$results_ar_size; $l++){ if($results_ar[$l] ne $results_ar_row){ #print STDOUT "$results_run_ar[$l] : $results_ar[$l]\n"; $cur_run = $results_run_ar[$l]; $_ = $results_ar[$l]; @out_row_ar = split; write; }#if $results_ar_row = $results_ar[$l]; }#for