RE: Incrementing count

2004-03-30 Thread Ichim, Adrian N.
 
 - Original Message -
 From: [EMAIL PROTECTED]
 To: 
 Sent: Monday, March 29, 2004 6:20 AM
 Subject: Incrementing count
 
 
  I'm sorry, the previous subject should have been changed. 
 My apologies.
 
 
while (FILE) {
 $counter++;
  }
 
  I know this is probably simple, but how would I increment by 20? In 
  other words, $counter would increment 1 time for every 
 twenty lines of the file?
 Any
  help would be appreciated.
 
 
while (FILE) {
 $counter=$counter +20;
  }

The result I think the OP wants to achieve is:

$counter = $line = 0;
while (FILE)
{
$counter++  unless ($line++ % 20);
}

This one increments $counter every time $line is an multiple of 20.

Even better :

$counter = 0;
while (FILE)
{
$counter++  unless ($. % 20);
}

[See perldoc perlvar]

Adrian Ichim



**
PLEASE NOTE: The above email address has recently changed from a previous naming 
standard -- if this does not match your records, please update them to use this new 
name in future email addressed to this individual.

This message and any attachments are intended for the 
individual or entity named above. If you are not the intended
recipient, please do not forward, copy, print, use or disclose this 
communication to others; also please notify the sender by 
replying to this message, and then delete it from your system. 

The Timken Company
**


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




Re: Incrementing count

2004-03-29 Thread Chance Ervin
- Original Message -
From: [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Monday, March 29, 2004 6:20 AM
Subject: Incrementing count


 I'm sorry, the previous subject should have been changed. My apologies.


   while (FILE) {
$counter++;
 }

 I know this is probably simple, but how would I increment by 20? In other
 words, $counter would increment 1 time for every twenty lines of the file?
Any
 help would be appreciated.


   while (FILE) {
$counter=$counter +20;
 }

--
-
InteleNet Communications Inc.   Help me help you.
Chance Ervin - SCSA  -- Jerry Maguire
Oracle Certified Professional
Operations Supervisor


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




Re: Incrementing count

2004-03-29 Thread James Edward Gray II
On Mar 29, 2004, at 8:20 AM, [EMAIL PROTECTED] wrote:

I'm sorry, the previous subject should have been changed. My apologies.

  while (FILE) {
   $counter++;
}
I know this is probably simple, but how would I increment by 20? In 
other
words, $counter would increment 1 time for every twenty lines of the 
file? Any
help would be appreciated.
$counter += 20;

James

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



Re: Incrementing count

2004-03-29 Thread Randy W. Sims
Chance Ervin wrote:
- Original Message -
From: [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Monday, March 29, 2004 6:20 AM
Subject: Incrementing count


I'm sorry, the previous subject should have been changed. My apologies.

 while (FILE) {
  $counter++;
}
I know this is probably simple, but how would I increment by 20? In other
words, $counter would increment 1 time for every twenty lines of the file?
Any

help would be appreciated.



   while (FILE) {
$counter=$counter +20;
 }
I think he meant the other way. Try something like:

while (FILE) {
  ++$counter unless $. % 20;
}
$. is the line count; see 'perldoc perlop'

Randy.

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



RE: Incrementing count

2004-03-29 Thread Timothy Donahue
Or this can be further simplified:

while (FILE) {
$counter += 20;
}

The += operator is equivilent to saying add the value then assign it to
the variable.

Tim Donahue

 -Original Message-
 From: Chance Ervin [mailto:[EMAIL PROTECTED] 
 Sent: Monday, March 29, 2004 1:03 PM
 To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
 Subject: Re: Incrementing count
 
 
 - Original Message -
 From: [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Sent: Monday, March 29, 2004 6:20 AM
 Subject: Incrementing count
 
 
  I'm sorry, the previous subject should have been changed. 
 My apologies.
 
 
while (FILE) {
 $counter++;
  }
 
  I know this is probably simple, but how would I increment 
 by 20? In other
  words, $counter would increment 1 time for every twenty 
 lines of the file?
 Any
  help would be appreciated.
 
 
while (FILE) {
 $counter=$counter +20;
  }
 
 --
 -
 InteleNet Communications Inc.   Help me help you.
 Chance Ervin - SCSA  -- Jerry Maguire
 Oracle Certified Professional
 Operations Supervisor
 
 
 -- 
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 http://learn.perl.org/ http://learn.perl.org/first-response
 
 
 

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




RE: Incrementing count

2004-03-29 Thread Bob Showalter
[EMAIL PROTECTED] wrote:
 I'm sorry, the previous subject should have been changed. My
 apologies. 
 
 
   while (FILE) {
$counter++;
 }
 
 I know this is probably simple, but how would I increment by 20? In
 other words, $counter would increment 1 time for every twenty lines
 of the file? Any help would be appreciated.

Here's one possible way:
 
   $counter++ unless $. % 20;

$. is last line number read (starting at 1; see perldoc perlvar)

So $. % 20 will be 0 (false) for line 20, 40, 60, etc. Just increment your
counter then.

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




Re: Incrementing count

2004-03-29 Thread Smoot Carl-Mitchell
On Mon, 29 Mar 2004 12:08:33 -0600
James Edward Gray II [EMAIL PROTECTED] wrote:

 On Mar 29, 2004, at 8:20 AM, [EMAIL PROTECTED] wrote:
 
  I'm sorry, the previous subject should have been changed. My
  apologies.
 
 
while (FILE) {
 $counter++;
  }
 
  I know this is probably simple, but how would I increment by 20? In 
  other
  words, $counter would increment 1 time for every twenty lines of the
  file? Any
  help would be appreciated.
 
 $counter += 20;

This is not what the poster asked. This will increment the counter by 20
for every line of the file. Something like this does what the original
poster wants:

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
Systems/Network Architect
email: [EMAIL PROTECTED]
cell: +1 602 421 9005
home: +1 480 922 7313

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




Re: Incrementing count

2004-03-29 Thread R. Joseph Newton
[EMAIL PROTECTED] wrote:

 I'm sorry, the previous subject should have been changed. My apologies.

   while (FILE) {
$counter++;
 }

 I know this is probably simple, but how would I increment by 20? In other
 words, $counter would increment 1 time for every twenty lines of the file? Any
 help would be appreciated.

You probably need two counters then--one outside the loop, and one inside.  There
is a Perl variable that representsthe loop counter also, but you might as well be
explicit, since your focus seems to be on the loop count.

Can you tell us what your overall purose is?  That would give us a much better
idea of what advice to give.

Joseph


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




Re: Incrementing count

2004-03-29 Thread R. Joseph Newton
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




Re: Incrementing count

2004-03-29 Thread R. Joseph Newton
Smoot Carl-Mitchell wrote:

Hi Carl-Mitchell,

Please stay on the list.  I will address that.

 I'll take this offline, since I do not think it should be on the list

I disagree.  With all due respect, you and I have not developed a personal
correspondence.  There are some very good reasons for the custom of keeping our
discussions on-list.

  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.

 I do not think it is a disservice. I thought the specifications were
 very clear. I think you were mistaken in your interpretation and I was
 pointing it out. I have no problem being corrected when I am wrong. And
 we can certainly discuss offline our diagreement and whether I am doing
 a disservice to students.

No.  The subject of learning itself, the learning process, and what helps or
hinders or helps the learning process, is a discussion that students using the
list as a resource should be aware of.  It is not meant as a comment on any
person, but on a need for care in specification very particular to the task of
learning to program.

 I do not think I was. Can you elaborate on
 what you mean by disservice.

That is fine, although it was not me you were responding to in the post to which
I responded.  I suspect you are right about the actual intent.  All I can tell
you is that I have watched a lot of traffic on this list, and I have seen a lot
of floundering where people have too quickly re-interpreted a specification.


 Mu interpretation of the OP requirments was something like processing an
 input file with 20 lines per entry and counting the entries. That is a
 fairly practical problem.

Agreed.


 Smoot Carl-Mitchell

I am sorry if you take any personal offense here.  No offense was intended, only
discussion.

Joseph


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