in reply to Re^2: why such an error?
in thread why such an error?
There are a number of ways you could do it:
$dup{$row[3]} = $dup{$row[3]} + 1; # Has trouble with undef $dup{$row[3]} += 1; ++$dup{$row[3]}; $dup{$row[3]}++;
+= and ++ are magical to the extent that they can update an undef value without complaint. That is often very useful, especially where a hash or array element is autovivified. For example, if you are using a hash to count the number of occurrences of words in a string you could:
++$wordCount{$_} for split ' ', $string;
which generates an entry in %wordHash for each word and increments the count - very clear and concise.
|
|---|