Smoot Carl-Mitchell wrote:

> This is not what the poster asked.

Actually, yes it is, at least part of it.  He said "would I increment by 20?...
$counter would increment 1 time for every twenty lines of the file?"

> This will increment the counter by 20
> for every line of the file.

Read without re-interpretation, this indicates precisely to increment once, by
20, for each 20 lines.

> Something like this does what the original
> poster wants:

Perhaps, but is it what he asked for.  I think it does a disservice to students
to silently fill in the gaps in their logic.  You can give them the right answer
to a particular problem, but still leave them without an awareness of the need
to be precise in their specification.

> while (<FILE>) {
>         $counter++ if ! ($. % 20);
> }
>
> This increments the counter by one for every 20 lines of input. $. is
> the input line counter. % is the modulo operator. See perlvar for the
> details on $. and perlop for the modulo operator.
>
> --
> Smoot Carl-Mitchell

That does help, presuming that the OP had actually misstated his desired
results.

The closest I can come to the desired results as expressed [since I don't much
like the cryptic $. built-in] is

my $counter = 0;
my $inner_counter = 0;
while (<FILE>) {
   $inner_counter++;
   $counter +=20 unless $inner_counter % 20;
}

Which seems pretty damned pointless to me, but is what the OP asked for.  Better
that we guide him towards the practice of carefully defining his problem.

Joseph


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to