Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: New to coding - Looping code to save time

by duelafn (Parson)
on May 11, 2012 at 15:50 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://970047]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (2)
As of 2024-04-26 00:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found