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. ] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]