in reply to Incrementing a Hash Value
// I am making the assumption that the syntax // error here is just a typo ( missing a $ in front // of the second thes_name) . $thes_name{$fields[1]} = thes_name{$fields[1]}++;
What this code does is effectively the following:
Start) $thes_name{$fields[1]} has a value of 1
1) Resolves $thes_name{$fields[1]} to its value "1".
2) Increments $thes_name{$fields[1]} to "2"
3) Sets $thes_name{$fields[1]} to the previously resolved value, "1".
End) Thus $thes_name always stays at "1".
Because you used a "post-increment" it happens after the variable is already resolved. If you had used a "pre-increment", ++$thes_name{$fields[1]}, if would have done what you expected -- but marvells answer for that is better.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Incrementing a Hash Value
by Abigail-II (Bishop) on Jun 14, 2002 at 12:04 UTC | |
by Juerd (Abbot) on Jun 14, 2002 at 13:09 UTC | |
|