Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Counter and # of output lines not equal and should be

Status
Not open for further replies.

netman4u

Technical User
Mar 16, 2005
176
US
Hello all,

I have a baffling problem that I cannot figure out. I have a bunch of IF loops in a FOR loop. Here is an example:

Code:
if ($open_month	eq $rpt_month) {
	$open_cnt{$rpt_month}++;
	# Uncomment the line below to dump the tickets counted for this count to a file
	print OPEN3 "$_\n";
}

The problem is after the program, my counter equals 2391 yet there are only 244 lines being written to my OPEN3 file.

Below is the whole big foreach loop so you can see it. I appologize, it is quite big:

Code:
	foreach (@problem) { # Start Problem Table loop
		#
		#  Problem Table processing
		#
		my ($company, $logical_name, $numberprgn, $assignment, $uis_elapsed_start_time, $close_time, $res_anal_code,
		 	$user_priority, $severity_code ) = split (/,/);
		#
		#  Exclude entries with no logical name.
		#
		next unless ($logical_name);
		#
		# Exclude entries where the dates are non digits (headings)
		#
		next unless ($uis_elapsed_start_time =~ /\d+/ || $close_time =~ /\d+/);
		###############################################################################################
		#
		#  Problem Table exceptions
		#
		###############################################################################################
		next if ($res_anal_code =~ /cancel/i);
		next if ($res_anal_code =~ /duplicate/i);
		next if ($res_anal_code =~ /testing/i);
		next if ($res_anal_code =~ /information/i);		
		#
		#  Exception for Morgan Stanley
		#
		if ($key eq "mwd") {$severity_code = $user_priority;}
		#
		#  Joint customer exceptions
		#
		next if ($assignment =~ /MODIFY/i);  
		#
		# Split ticket open and close dates into chunks
		#
		($open_month, $open_day, $open_year, $junk2) = split (/-/,$uis_elapsed_start_time);
		($close_month, $close_day, $close_year, $junk1) = split (/-/,$close_time);
		#
		# Convert $severiy_code
		#
		if ($severity_code =~ "1") {$severity_code = 'critical';}
		if ($severity_code =~ "2") {$severity_code = 'warning';}
		if ($severity_code =~ "3") {$severity_code = 'normal';}
		if ($severity_code =~ "4") {$severity_code = 'low';}
		if ($severity_code =~ "5") {$severity_code = 'very low';}
		################################################################################################
		#
		# Count open, closed and backlog tickets for each month of the 4 months chart. We will use these
		# for the one months charts as well.
		#		
		################################################################################################
		#
		# Closed tickets for last 4 months
		#
		if ($close_month eq $last4months[0]) {
			$closed_cnt{$last4months[0]}++;
			# Uncomment the line below to dump the tickets counted for this count to a file
			#print CLOSE0 "$_\n";
		}
		if ($close_month eq $last4months[1]) {
			$closed_cnt{$last4months[1]}++;
			# Uncomment the line below to dump the tickets counted for this count to a file
			#print CLOSE1 "$_\n";
		}
		if ($close_month eq $last4months[2]) {
			$closed_cnt{$last4months[2]}++;
			# Uncomment the line below to dump the tickets counted for this count to a file
			#print CLOSE2 "$_\n";
		}
		if ($close_month eq $rpt_month) {
			$closed_cnt{$rpt_month}++;
			# Uncomment the line below to dump the tickets counted for this count to a file
			#print CLOSE3 "$_\n";
		}
		#
		# Opened tickets last 4 months
		#
		if ($open_month	eq $last4months[0]) {
			$open_cnt{$last4months[0]}++;
			# Uncomment the line below to dump the tickets counted for this count to a file
			#print OPEN0 "$_\n";
		}
		if ($open_month	eq $last4months[1]) {
			$open_cnt{$last4months[1]}++;
			# Uncomment the line below to dump the tickets counted for this count to a file
			#print OPEN1 "$_\n";
		}
		if ($open_month	eq $last4months[2]) {
			$open_cnt{$last4months[2]}++;
			# Uncomment the line below to dump the tickets counted for this count to a file
			#print OPEN2 "$_\n";
		}
		if ($open_month	eq $rpt_month) {
			$open_cnt{$rpt_month}++;
			# Uncomment the line below to dump the tickets counted for this count to a file
			#print OPEN3 "$_\n";
		}
		#
		# Ending backlog last 4 months
		#
		if ($open_month <= $last4months[0]) {
			if ($close_month) {
				if ($close_month > $last4months[0]) {
					$end_backlog{$last4months[0]}++;
					# Uncomment the line below to dump the tickets counted for this count to a file
					#print END2 "$_\n";
				}	
			}else{
				$end_backlog{$last4months[0]}++;
				# Uncomment the line below to dump the tickets counted for this count to a file
				#print END2 "$_\n";
			}
		}
		if ($open_month <= $last4months[1]) {
			if ($close_month) {
				if ($close_month > $last4months[1]) {
					$end_backlog{$last4months[1]}++;
					# Uncomment the line below to dump the tickets counted for this count to a file
					#print END2 "$_\n";
				}	
			}else{
				$end_backlog{$last4months[1]}++;
				# Uncomment the line below to dump the tickets counted for this count to a file
				#print END2 "$_\n";
			}
		}
		if ($open_month <= $last4months[2]) {
			if ($close_month) {
				if ($close_month > $last4months[2]) {
					$end_backlog{$last4months[2]}++;
					# Uncomment the line below to dump the tickets counted for this count to a file
					#print END2 "$_\n";
				}	
			}else{
				$end_backlog{$last4months[2]}++;
				# Uncomment the line below to dump the tickets counted for this count to a file
				#print END2 "$_\n";
			}
		}
		if ($open_month le $rpt_month) {
			if ($close_month) {
				if ($close_month gt $rpt_month) {
					$end_backlog{$rpt_month}++;
					# Uncomment the line below to dump the tickets counted for this count to a file
					#print END3 "$_\n";
				}
			}else{
				$end_backlog{$rpt_month}++;
				# Uncomment the line below to dump the tickets counted for this count to a file
				#print END3 "$_\n";
			}
		}
		
		
		#
		# Starting backlog. We only need it for the current month
		#
		if ($open_month < $rpt_month) {
			unless ($close_month) {
				$start_backlog{$rpt_month}++;
				# Uncomment the line below to dump the tickets counted for this count to a file
				#print START3 "$_\n";
			}
			if ($close_month >= $rpt_month ) {
				$start_backlog{$rpt_month}++;
				# Uncomment the line below to dump the tickets counted for this count to a file
				#print START3 "$_\n";
			}
		}
		#
		# Count tickets closed for the report month.
		# Count res_anal_codes for the month
		#
		if ($close_month == $rpt_month) {
			
			$close_cnt++; # Tickets Closed during the current month
			# Uncomment the line below to dump the tickets counted for this count to a file
			#print CLOSE4 "$_\n";
			#
			# Count up the Problem types at resolution
			#
			if 	($res_anal_code =~ /customer/i) 	{$changes++;}
			elsif 	($res_anal_code =~ /telco/i) 		{$telco++;}
			elsif 	($res_anal_code =~ /power/i) 		{$power++;}
			elsif 	($res_anal_code =~ /server/i) 		{$server++;}
			elsif 	($res_anal_code =~ /application/i) 	{$application++;}
			else {$other++;}
		}
		#
		#  Handle defaults
		#
		unless ($severity_code) {$severity_code="critical";}
		unless ($user_priority) {$user_priority = "S1";}
		#
		#
		#  For each entry in the problem table, loop through the device table, perform device table exclusions
		#  then match the logical_name from the problem table query with the logical_name from the device table
		#  query and if a match is found, populate the merge hash with the device table matching fields. If
		#  a match is not found, use default data to fill the hash with device table information.
		#
		#
		$problem{$logical_name}=($_);
		my $dev_loop_cnt = 0;
		foreach (@device) { # Start Device Table processing.
			#
			# Device Table Processing
			#
			($log_name, $type, $uis_tier, $uis_fstatus, $uis_managed_date, $uis_deactivated_date ) = split (/,/);
			#
			# Make sure there is a Tier associated with the ticket.
			#
			unless ($uis_tier) {$uis_tier = 'No Tier';}
			########################################################################################
			#
			#  Device Table exceptions
			#
			########################################################################################
			#
			#  Joint customer exceptions
			#
			next unless ($logical_name =~ /\.na\.$key$/i);
			next if ($log_name	=~ /default/i	);
			next if ($log_name	=~ /imac/i	);
			next if ($type		=~ /circuit/i	);
			next if ($type		=~ /type/i	);
			if ($uis_tier eq 'T1') {$uis_tier = 'Tier 1';}
			if ($uis_tier eq 'T2') {$uis_tier = 'Tier 2';}
			if ($uis_tier eq 'T3') {$uis_tier = 'Tier 3';}
			if ($uis_tier eq 'T4') {$uis_tier = 'Tier 4';}
			if ($uis_tier eq 'T5') {$uis_tier = 'Tier 5';}
			#
			# Look for a logical name match
			#
			if (exists $problem{$log_name}) {#look up problem hash for common key to device and problem
				#
				# Merge it all. Set the loop counter to 1 as well since we found a match.
				#
				$dev_loop_cnt = 1;
				my @afh = ("$logical_name,$numberprgn,$assignment,$open_month,$close_month,$open_year,$close_year,$rpt_yr,$rpt_month,$res_anal_code,$severity_code,$type,$uis_support_level,$uis_tier,$uis_fstatus,$uis_managed_date,$uis_deactivated_date");
				$merge{$numberprgn} = [@afh]; 
				$match_cnt++;
			}
		}# End Device Table Loop
		if ($dev_loop_cnt == 0) {
			#############################################################################################  
			#
			#  Could not find a match in the device table query. Populate with default values
			#
			#############################################################################################
			# Assign default value to type based on assignment
			# 
			if ($assignment		=~ /nccbb/i) {
				$type = "network";
			}elsif ($assignment =~ /smcbb/i) {
				$type = "system";
			}elsif ($assignment =~ /sccbb/i) {
				$type = "security"
			}elsif ($assignment =~ /iptbb/i) {
				$type = "VOIP";
			}
			#
			# Assign default value to uis_tier
			#
			$uis_tier = "No Tier";
			#
			# Merge it all
			#
			my @afh = ("$logical_name,$numberprgn,$assignment,$open_month,$close_month,$open_year,$close_year,$rpt_yr,$rpt_month,$res_anal_code,$severity_code,$type,$uis_support_level,$uis_tier,$uis_fstatus,$uis_managed_date,$uis_deactivated_date");
			$merge{$numberprgn} = [@afh]; 
			$nomatch_cnt++;	
		}

	} # End Problem Table Loop

As always, any help is appreciated,

Nick
 
What are the values for @last4months[0..3] and $rpt_month ?
Could it be possible that $rpt_month equals one of the last4months ?

--------------------

Denis
 
I figured it out. I was not initializing my counters for each iteration of the main loop.

Thanks
 
you have some suspect lines in your code:

Code:
if ($severity_code =~ "1") {$severity_code = 'critical';}
        if ($severity_code =~ "2") {$severity_code = 'warning';}
        if ($severity_code =~ "3") {$severity_code = 'normal';}
        if ($severity_code =~ "4") {$severity_code = 'low';}
        if ($severity_code =~ "5") {$severity_code = 'very low';}

mainly the:

$severity_code =~ "2"

The way you have it they are regexp's when it looks like they should be just numeric comparisons:

$severity_code == 2

but maybe not.
 
Well spotted KevinADC,

But also the $severity_code = 'warning' (and others) are also very suspect.
String comparisons should be $severity_code [red]eq[/red] 'warning'.


Trojan.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top