> > The following works the same and may or may not be easier to > > understand/maintain. > > $tokenCount{$_} is automatically created with a value of 0 when first > > called, and > > then is incremented to 1, so you don't have to test or create it yourself. > > > > my @tokens = split /:/; > > for (@tokens) { > > $tokenCount{$_}++ > > } # for > > Wow! It works. I'm not sure that's such a good thing, though. How does > one ditinguish, then, between 0 as a meaningful value, and a still-undefined > variable?
mainly: perldoc -f exists sometimes: perldoc -f defined > I think, for the sake of healthy discipline, at least, that I would > stick with explicitly assigning a numerical value to my variables > before executing any other operations on them. Implicit casts from > undef? Boolean--aye, any other type, Nay! If you wrote the following (moved from above) code, then you are already doing it. When the if statement evaluates $tokenCount{$_}, it creates it and assigns a value to it (I don't remember what the value is, but it evaluates to ""/0/false). > > > my @tokens = split /:/; > > > foreach (@tokens) { > > > if ($tokenCount{$_}) { > > > $tokenCount{$_}++; > > > } else { > > > $tokenCount{$_} = 1; > > > } > > > } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]