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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loop in loop problem

Status
Not open for further replies.

nfaber

Technical User
Oct 22, 2001
446
US
Can anyone see aproblem with my basic logic in this code?

Code:
foreach $prob (@problem) { # Start Problem Table loop
	chomp $prob;
	my ($company, $logical_name, $numberprgn, $assignment, $uis_elapsed_start_time, $close_time, $res_anal_code,
		$user_priority, $severity_code ) = split (/,/, $prob);
		foreach $dev (@device) { # Start Device Table loop.
			#
			# Device Table Processing
			#
			chomp $dev;
			($log_name, $type, $subtype, $uis_support_level, $uis_tier, $uis_fstatus, $uis_managed_date, $uis_deactivated_date ) = split (/,/, $dev);
			$match_cnt = 0;
			next unless ($log_name eq $logical_name);
			#
			# Merge it all
			#
			$match_cnt++;
			$dev_loop_cnt++;
			#print LOG "$assignment, $res_anal_code, $user_priority, $severity_code, $type, $uis_support_level, $uis_tier, $uis_fstatus\n";
			push (@data, $assignment, $res_anal_code, $user_priority, $severity_code, $type, $uis_support_level, $uis_tier, $uis_fstatus);
			} # End device table loop
		if ($match_cnt = "0") {
			push (@data, $assignment, $res_anal_code, $user_priority, $severity_code, $type, $uis_support_level, $uis_tier, $uis_fstatus);
			$nomatch_cnt++;
		} # End default loop
}
print LOG "Found $dev_loop_cnt matching record from DEVICE and PROBLEM Tables\n";
print LOG "Generated $nomatch_cnt records using defaults\n\n";

When I run it. I get this for the prints:

Code:
Found 466 matching record from DEVICE and PROBLEM Tables
Generated 0 records using defaults

It does not seem to be getting the default loop. WHile it may be possible that it find a natch for every record. I suspect it would not.

Thanks

I got a Biz Degree! How the h*ll did I get here?
 
OK, I found one problem already. This line:

Code:
 if ($match_cnt = "0") {

needs to be:

Code:
 if ($match_cnt == "0") {

now I am getting:

Code:
Found 466 matching record from DEVICE and PROBLEM Tables
Generated 466 records using defaults

I got a Biz Degree! How the h*ll did I get here?
 
If the prints you get are not the ones you want, then the problem is either in the rest of the code, or is a logical error in the loop depending on the stracture of your arrays @problem and @device



TIMTOWTDI
 
It does not seem to be getting the default loop.
What default loop? I don't see one in your code for it to get to. It's difficult to see what's going wrong without knowing what it's supposed to do, but my guess is that this line is on the wrong place:
Code:
            $match_cnt = 0;
You're setting [tt]$match_cnt[/tt] to zero in each iteration of the device table loop. So when you get to the [tt]if[/tt] statement, it'll be 1 if the very last device in the array is a match, otherwise it'll be 0. Somehow I don't think that's what you want - try resetting it just before this line instead:
Code:
        foreach $dev (@device)

-- Chris Hunt
Webmaster & Tragedian
Extra Connections Ltd
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top