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

Generating a chart 2

Status
Not open for further replies.

nfaber

Technical User
Oct 22, 2001
446
US
Hello all,

I am in the process of writing some code that generates a chart. I can probably figure this out, but I though someone might have some ideas on an easy way to do this and want to poke at some code on a Sunday. The chart needs to look like this:

Code:
troubleNumber chart:
devType, critical, warning, normal
router, 27, 2, 3
switch, 3, 5, 7,

I need to count all the severities of tickets for each device type in an array. The array looks like this called @type_chart that contains the type (ex, router) and the severity (ex, normal) for each ticket:
Code:
server,normal
server,normal
server,normal
server,normal
server,normal
pc,normal
server,warning
server,normal
server,normal
server,normal
pc,normal
server,normal
server,normal
server,normal
pc,normal
server,critical
server,normal
server,normal
server,normal
router,normal
router,normal
server,normal
server,normal
server,normal
server,normal
server,normal
router,critical
server,normal
server,normal
server,normal
server,normal
server,normal
server,normal
server,normal
server,critical
server,normal
server,warning
server,normal
server,normal
server,normal
server,normal
server,normal
server,normal
server,normal
pc,normal
pc,normal
pc,normal
server,normal
server,normal
pc,normal
server,normal
server,normal
server,normal
server,normal
server,normal
server,normal
server,critical
server,normal
server,normal
server,normal
server,normal
pc,normal
server,normal
server,warning
pc,normal
server,normal
server,warning
server,normal
server,normal
server,normal
server,normal
router,normal
server,normal
server,normal
router,normal
server,normal
server,warning
server,normal
server,normal
router,normal
server,normal
server,normal
server,normal
server,normal
server,normal
server,critical
server,normal
pc,warning
server,normal
server,normal
server,normal
pc,warning
server,warning
server,normal
server,normal
server,critical
server,normal
pc,normal
server,normal
server,normal
pc,normal
server,normal
server,normal
server,normal
server,normal
pc,normal
server,normal
server,normal
server,normal
server,normal
server,normal
server,normal
server,normal
server,warning
server,normal
server,warning
server,normal
pc,normal
server,critical
pc,normal
server,normal
server,normal
server,normal
server,normal
pc,normal
server,normal
server,normal
server,warning
server,normal
server,normal
pc,normal
server,normal
server,normal
server,normal
server,normal
server,normal
server,normal
server,normal
server,critical
pc,warning
server,normal
server,normal
server,normal
pc,normal
server,normal
server,normal
server,normal
server,normal
server,normal
server,normal
server,normal
server,normal
server,normal
server,normal
server,warning
server,normal
server,normal
server,warning
server,warning
server,normal
server,critical
server,normal
server,normal
server,normal
server,critical
pc,normal
server,normal
server,normal

Here is the code I have so far:

Code:
push (@type_chart, join (',',$type,$severity_code);
my %prob_type =();
my @type_critical = ();
my @type_warning = ();
my @type_normal = ();
foreach (@type_chart) {
	my ($typ,$cri) = split (/,/);
	#print "$_\n";
	if ($_ =~ /critical/i) { push (@type_critical, $_);}
	if ($_ =~ /warning/i) { push (@type_warning, $_);}
	if ($_ =~ /normal/i) { push (@type_normal, $_);}
}
foreach $type_new (@types_new) {
	foreach $var1 (@type_critical) {
		next unless $var1 =~ /$type_new/;
		$prob_type{$var1}++;
	}
}
# print records to file
print LOG "Problem Types and counts\n";
foreach ( keys %prob_type ) {
	print LOG "$_ $prob_type{$_}\n";
}

Here is the output I am getting. (I threw some routers in the array above):

Code:
Problem Types and counts
server,critical 310960
pc,critical 2535


I was getting ready to create another foreach loop for the normal and warning tickets, and thought there may be a better way.

Thanks

I got a Biz Degree! How the h*ll did I get here?
 
the ternary operator is one of my favorites:

Code:
condition ? true : false

its basically a short cut for:

Code:
if (condition) {
  true
}
else {
   false
}

I love to use it to check if system functions return true, such as:

rmdir($dir) ? $success++ : $fail++;
 
'Course you could just assign the result to a variable.
Code:
my $success = rmdir($dir);
die qq(rmdir failed!\n) unless $success;
 
mikevh,

certainly could do it that way. In the example line I posted is keeping a running total of how many times the rmdir() function succeeded or failed looping over an array of directories, something like:

Code:
for (@list) {
   if (-d) {
      rmdir($dir) ? $success++ : $fail++;
}
return($success,$fail)

But if I wanted to "die" in the event rmdir() returned false I would do it like you posted, or without the scalar:

rmdir($dir) or die "rmdir failed: $!";
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top