in reply to New to coding - Looping code to save time
Something like:
## Note: INDEX STARTS AT 0, I show day number here for convenience: ## Day: 1, 2, 3, 4, 5, ... my @start = ( 7, 6, 7, 0, 9, ... ); my @stop = (15, 16, 18, 0, 12, ... ); my @personal = ( 1, 1, 0, 0, 1.5, ... ); my (@daily, @busi, $daily_total, $busi_total, $pers_total); # array indices start at zero: for my $i (0..30) { next unless $stop[$i] > 0; $daily[$i] = $stop[$i] - $start[$i]; $busi[$i] = $daily[$i] - $personal[$i]; $daily_total += $daily[$i]; $busi_total += $busi[$i]; $pers_total += $personal[$i]; }
Update: Ninja'd by kennethk - oh well. Note that my solution will save the daily totals while kennethk's solution uses temporary variables. Use whichever is appropriate for your situation. (and do read the references provided by kennethk).
Good Day,
Dean
|
|---|