I was reading the adding multiple value to a hash thread and I checked out the perldoc and I was wondering if this code is ok:
my @ticTblCnts = ();
my $tableIndex = 0;
foreach my $loc (@out_locations) {
foreach my $crit(@out_priorities) {
foreach my $ty (@out_types) {
my $combin =...
Yup, that was it Paul. I tried to get cute and initialize all my counters in the same line. Sometimes we should leave well enough alone.
my $changes = 0;
my $power = 0;
my $telco = 0;
my $application = 0;
my $server = 0;
my $other = 0;
I got a Biz Degree! How the h*ll did I get here?
I've been playing with some code to assign a zero to a variable if undefined but it is not working. This is excerts from a larger program.
my ($changes,$telco,$application,$server,$other) = 0;
foreach $res_anal_code (@res_code) {
if ($res_anal_code =~ /customer/i){$changes++;}
elsif...
Ok Paul...how about this one:
my $date = "03-20-2005";
my ($month,$day,$year) = split (/-/, $date);
Is $month an integer or string?
I got a Biz Degree! How the h*ll did I get here?
Hello all,
How can I tell for sure if the variable I am operating on is a string or an integer?
Can't 01 also be a string "01"??
Thanks
I got a Biz Degree! How the h*ll did I get here?
IC!
@{$h{$k}}{@types} = map {defined($_)? $_: 0} @{$h{$k}}{@types};
"if" defined($_) ? "then" map $_ to our array
"else" map a 0.
nice.
Nick
I got a Biz Degree! How the h*ll did I get here?
Thanks Mike,
Took your advice and now $type is $thing. Studying map. I see how this works:
my @words = map { s/[.,!\?]\B//g; split; } <FILE>;
map returns a list, so you will usually assign it to some type of array or hash. In this example map is a loop that runs two commands on <FILE> the...
Thanks Mike,
It does not seem to matter. This works:
my ($type, $cri) = split /,/;
$h{$type}->{$cri}++;
and this works as well:
my ($cri, $type) = split /,/;
$h{$cri}->{$type}++;
Both give (not based on the above exact data, but the format is...
Tony,
That is not all my code. There are alot of "next unless" and "if" staments in each loop, but they do not apply to my logic problem and I did not want to complicate the code needlessly. You are right about the closing braces. I just cut and pasted the applicable code. The braces are in...
Ok...I believe I got it. I just swapped the $cri and $type:
my %h;
my @types = qw(critical warning normal);
foreach (@type_chart) {
chomp;
my ($cri, $type) = split /,/;
$h{$cri}->{$type}++;
}
print LOG "Problem Types and counts\n\n";
#print LOG "devType, critical...
Thanks for the replies.
Tony, The difference is in the:
#Set defaults since a match was not found.
This represents the code that sets default values for each variable from the device loop split.
Mlibeson,
If I remove the "last;" from both loops, a record is generated for each entry in the...
A while ago I posted a question about a loop in a loop. Here is the basic structure:
foreach (@problem) {
my ($company, $logical_name, $numberprgn, $assignment, $uis_elapsed_start_time, $close_time, $res_anal_code,$user_priority, $severity_code ) = split (/,/)...
Thanks for all the replies. The reason I was leaning to Kevin's code is because I understood what he was doing. I try not to use code I do not understand anymore. That being said, I see what you are doing Mike, excepts for this line:
@{$h{$k}}{@types} = map {defined($_)? $_: 0}...
Thanks Kevin and Mike. I already used Kevin's code in my script and I DO need to:
How can I do that using Kevin's code?
Thanks,
Nick
I got a Biz Degree! How the h*ll did I get here?
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:
troubleNumber chart:
devType...
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.