Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
use warnings; use strict; my $counter=0; my $tot=0; my $wantedSentence; my $item; my @b=(0,0,0,0,0,0,0,0,0,0); my @a=(15,24,23,110,30,58,3,22,79,6); foreach my $numOfSentences (@a) { $tot=$tot + $numOfSentences; #accumulating totals to @b; $b[$counter]=$tot; $counter++; } print "@b\n"; $counter=0; $wantedSentence = 250; foreach $item (@b) { if($wantedSentence <= $b[$counter]) {$counter++;print "this sentence in chapter $counter";last;} $counter++; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: chapters,sentences, and arrays
by brsaravan (Scribe) on Oct 21, 2008 at 10:45 UTC | |
|
Re: chapters,sentences, and arrays
by johngg (Canon) on Oct 21, 2008 at 14:11 UTC | |
by Narveson (Chaplain) on Oct 21, 2008 at 17:30 UTC | |
|
Re: chapters,sentences, and arrays
by luckypower (Beadle) on Oct 21, 2008 at 10:21 UTC | |
|
Re: chapters,sentences, and arrays
by Limbic~Region (Chancellor) on Oct 21, 2008 at 15:00 UTC | |
by JadeNB (Chaplain) on Oct 21, 2008 at 19:36 UTC | |
by Limbic~Region (Chancellor) on Oct 22, 2008 at 14:46 UTC | |
by ikegami (Patriarch) on Oct 22, 2008 at 18:22 UTC | |
by Perlbotics (Archbishop) on Oct 23, 2008 at 19:40 UTC | |
|
Re: chapters,sentences, and arrays
by Anonymous Monk on Oct 21, 2008 at 16:08 UTC |