Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Simplify HoH code

by pme (Prior)
on Dec 03, 2017 at 11:04 UTC ( #1204787=note: print w/replies, xml ) Need Help??


in reply to Simplify HoH code

Hi greetsathya,

I reworked your snippet code. It is probably not exactly what you need but I hope you can find useful details in it.

#!/usr/bin/perl use warnings; use strict; my @month = qw/JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC/; my $hash = { 2 => { W1 => 10.14, W2 => 11.22, }, 3 => { W1 => 33.17, W2 => 44.44, }, 4 => { W1 => 55.00, W2 => 66.66, }, }; my $lim = { 2 => { W1 => { L => 11, U => 14 }, W2 => { L => 13, }, }, 4 => { W2 => { L => 13.02, U => 15 }, }, }; for my $month ( sort keys %$hash ) { print "$month[$month-1]:\n"; for my $week ( sort keys %{$hash->{$month}} ) { my $lower = defined $lim->{$month}->{$week}->{L} ? $lim->{$month}- +>{$week}->{L} : 0; # min value my $upper = defined $lim->{$month}->{$week}->{U} ? $lim->{$month}- +>{$week}->{U} : 999; # max value my $value = $hash->{$month}->{$week}; my $below = ($value < $lower) ? sprintf('%6.2f', $value) : ''; my $above = ($value > $upper) ? sprintf('%6.2f', $value) : ''; my $in = ($value >= $lower and $value <= $upper) ? sprintf('%6.2f', $value) : ''; printf " %s %6.6s <%6.2f> %6.6s <%6.2f> %6.6s\n", $week, $below, $lower, $in, $upper, $above; } }

Replies are listed 'Best First'.
Re^2: Simplify HoH code
by greetsathya (Initiate) on Dec 03, 2017 at 11:51 UTC
    Thanks for your reply. Looking in to your code.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1204787]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2019-11-20 22:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Strict and warnings: which comes first?



    Results (103 votes). Check out past polls.

    Notices?