in reply to Re: Simplify HoH code
in thread Simplify HoH code
#!/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 } } } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Simplify HoH code
by haukex (Archbishop) on Dec 03, 2017 at 11:51 UTC | |
by greetsathya (Initiate) on Dec 03, 2017 at 12:37 UTC |