Firs thanks for quick reply. Yes , initially i had if else instead of given/when . I switched to given/when later maybe bad choice :( i will use perltidy for formatting. Actual content will be in that format. Ok to have hash there too insteadof bunch of variables but considering HoH loops & nested ifs, Not sure to check with this new hash against HoH second loop. i added updated script with few more variables and if checks and comment on exit/print information from perltidy output:
#!/usr/bin/perl use warnings; use strict; use feature "switch"; my %Hash = (); $Hash{"FEB"}{"W1"} = 10.14; $Hash{"FEB"}{"W2"} = 11.22; $Hash{"MAR"}{"W1"} = 33.17; $Hash{"MAR"}{"W2"} = 44.44; $Hash{"APR"}{"W1"} = 55.00; $Hash{"APR"}{"W2"} = 66.66; my $FEB_L1_W1 = 11; my $FEB_U1_W1 = 12.05; my $FEB_L1_W2 = 13.06; my $FEB_U1_W2 = 13.06; my $APR_L1_W1 = 1; my $APR_U1_W1 = 20; my $APR_L1_W2 = 33; my $APR_U1_W2 = 13.02; my $MAR_L1_W1 = -12.05; my $MAR_U1_W1 = -14.0; my $MAR_L1_W2 = 22.0; my $MAR_U1_W2 = -13.02; for my $month ( keys %Hash ) { print "$month: "; for my $week ( keys %{ $Hash{$month} } ) { print "$week=$Hash{$month}{$week} \n"; # Did you mean to hashloop for values here instead of hardcode +d variable names? if ( $month eq "FEB" ) { if ( $week eq "W1" ) { if ( ( $FEB_L1_W1 <= $Hash{$month}{$week} ) and ( $Hash{$month}{$week} <= $FEB_U1_W1 ) ) { print "month $month has f status for $week: $Hash{$month}{$week}\n"; } else { print "error: print something"; } } elsif ( $week eq "W2" ) { if ( ( $FEB_L1_W2 <= $Hash{$month}{$week} ) and ( $Hash{$month}{$week} <= $FEB_U1_W2 ) ) { print "month $month has f status for $week: $Hash{$month}{$week}\n"; } else { # print error key/value : $month $Hash{$month} $Hash{$mon +th}{$week} # get exit code } } } if ( $month eq "MAR" ) { if ( $week eq "W1" ) { if ( ( $MAR_L1_W1 <= $Hash{$month}{$week} ) and ( $Hash{$month}{$week} <= $MAR_U1_W1 ) ) { print "month $month has f status for $week: $Hash{$month}{$week}\n"; } else { # print error key/value : $month $Hash{$month} $Hash{$mon +th}{$week} # get exit code } } elsif ( $week eq "W2" ) { if ( ( $MAR_L1_W2 <= $Hash{$month}{$week} ) and ( $Hash{$month}{$week} <= $MAR_U1_W2 ) ) { print "month $month has f status for $week: $Hash{$month}{$week}\n"; } else { # print error key/value : $month $Hash{$month} $Hash{$mon +th}{$week} # get exit code } } } } }

In reply to Re^2: Simplify HoH code by greetsathya
in thread Simplify HoH code by greetsathya

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.