R. Joseph Newton wrote: > Mark Anderson wrote: > > > > It sounds like you need a count hash. You might try something > > > like: > > > > > > my @tokens = split /:/; > > > foreach (@tokens) { > > > if ($tokenCount{$_}) { > > > $tokenCount{$_}++; > > > } else { > > > $tokenCount{$_} = 1; > > > } > > > } > > > > 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? > > 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!
It's actually fine Joseph. There are a few places where an undefined value predictably becomes zero or the null string for convenience. I can't remember for the moment where it's documented, but it also works for the .= operator, so you can append to an undefined string withe the expected result. Cheers, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]