japhy,

    you are correct.  That it what I wanted to convey.  But with
everyone's input I understand what I was missing.


thanks again,

chad


On Tue, 2002-10-15 at 12:59, Jeff 'japhy' Pinyan wrote:
> On Oct 15, Rob said:
> 
> >From: "chad kellerman" <[EMAIL PROTECTED]>
> >
> >>      $hits{$hour} = $hits{$hour}+1;
> [snip]
> >> $hits{$hour} = $hits{$hour}+1;
> >>
> >> What it the best way to create a counter?
> >>
> >>   I have seen $var++, it would not work here I had to use +1.
> >
> >But I'd be interested to know why you had to use '+ 1'?
> 
> You are misinterpreting Chad's problem.  Chad didn't show EXACTLY the ++
> code he used, but I think I know.  Chad originally tried:
> 
>   $hits{$hour} = $hits{$hour}++;
> 
> but it did not work.  Why?  Because $hits{$hour}++ returns the PREVIOUS
> value of $hits{$hour} (0 in this case), then increments it by 1.  BUT then
> $hits{$hour} gets set back to 0 (the returned value).
> 
> Chad, you do not need to assign to $hits{$hour} again.  Simply saying
> 
>   $hits{$hour}++;
> 
> or, more computer-scientifically,
> 
>   ++$hits{$hour};
> 
> is sufficient.
> 
> -- 
> Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
> RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
> ** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
> <stu> what does y/// stand for?  <tenderpuss> why, yansliterate of course..
> [  I'm looking for programming work.  If you like my work, let me know.  ]
> 
-- 
Chad Kellerman
Jr. Systems Administrator
Alabanza Inc
410-234-3305

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to