Beefy Boxes and Bandwidth Generously Provided by pair Networks Frank
Think about Loose Coupling
 
PerlMonks  

Re: New to coding - Looping code to save time

by duelafn (Priest)
on May 11, 2012 at 15:50 UTC ( #970047=note: print w/ replies, xml ) Need Help??


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


Comment on Re: New to coding - Looping code to save time
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2014-04-21 01:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (489 votes), past polls