Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: New to coding - Looping code to save time

by duelafn (Vicar)
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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://970047]
help
Chatterbox?
[1nickt]: stevieb it turns out that Dell still has the Precision line of "mobile workstations", just not displayed on their main website. I found the Precision 7710 with 4k display/full-size keybd as req'd.
[1nickt]: List $2,788 (!), on sale for $1766, also a $200 coupon on the site thru 3/30 ... final price $1,566. Includes 3-yr on-site service.

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (7)
As of 2017-03-27 12:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (320 votes). Check out past polls.