Hi Rouilj, Yes, I was missing an "=" when I wrote my email but not on my real script so the question still applies.
Forget the real script's purpose for now, what I want to do is just print each pair of *key, value* from a perl hash using while (my ($key, $value) = each %%my_hash){ print ("Key: $key, Value: $value\n"); } The output I'm seeing is: Key: ??, Value: 1 Key: ??, Value: 5 Key: ??, Value: 3 ... All key values are incorrect (there should be IP addresses xxx.xxx.xxx.xxx). Instead, the code displays ??. It seems to me that the key values are not being stored correctly (is that even possible?) although I see on SEC debug messages that the key values are correct. Hopefully it makes more sense now. If not, I can provide more details. Thanks, Rafael On Apr 8, 2011, at 7:27 PM, John P. Rouillard wrote: > > In message <522e72e4-5144-4a68-b8e0-1b564bca8...@gmail.com>, > Rafael Bonilla writes: >> Now I have the following problem. >> >> I need to count how many times certain traffic comes from an IP address. I'm >> using perl hashes for that where the IP address is the key and the counter >> is the value. Fine so far. Then, I need to report that and for that I'm doin >> g the following inside eval: >> while ( my ($key, $val) each %%my_hash) { >> print (IP: $key, counter: $val); >> } > > Don't you need an = sign in there somewhere? > > while ( my ($key, $val) = each %%my_hash) { > ... > > Otherwise I think each is in scalar context. > >> The counter values print fine but all keys print some gibberish instead of >> the IP addresses. > > I can't explain how your example works at all. > >> Any suggestions? > > Also you could use each in scalar context and use: > > print ("IP: $key, counter: $$myhash{$key}"); > > or something along those lines. > > -- > -- rouilj > John Rouillard > =========================================================================== > My employers don't acknowledge my existence much less my opinions. ------------------------------------------------------------------------------ Xperia(TM) PLAY It's a major breakthrough. An authentic gaming smartphone on the nation's most reliable network. And it wants your games. http://p.sf.net/sfu/verizon-sfdev _______________________________________________ Simple-evcorr-users mailing list Simple-evcorr-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/simple-evcorr-users