> I don't understand this line:

 $ips{$source_ip}->{$dest_ip}++;

> how can you access and increment something that doesnt exist?

Fancy name: autovivification - perl, w/ your best interests at heart 
(generally) knows what you want to do, so it automagically creates the 
source_ip hash entry (if it doesn't exist), creates the anon-hash (ditto), 
adds a dest_ip key (ibid) and sees the incr. op, so set a value to zero 
and increments it - bingo
 $ips{$source_ip}->{$dest_ip}++;
 if ( $ips{$source_ip}->{$dest_ip} == 1 ) {
     print "First time $source_ip has sent $dest_ip packets!\n";
 }

On the other hand, autoV works for increment, but you should see a warning 
(you are using -w/strict right?) if you try::
 if ( $ips{$source_ip}->{$dest_ip} == 0 ) {
     print "First time $source_ip has sent $dest_ip packets!\n";
 }
 $ips{$source_ip}->{$dest_ip}++;

Here, if it *is* the first time, as dest_ip doesn't exist, you'll see:
Use of uninitialized value in numeric eq (==) at ....

In this case:
 unless ( $ips{$source_ip}->{$dest_ip} ) {
     print "First time $source_ip has sent $dest_ip packets!\n";
 }
 $ips{$source_ip}->{$dest_ip}++;

gets around that as there's no compare - basically you're checking for 
truth, existence or non-zero.

Make any sense?

a

Andy Bach, Sys. Mangler
Internet: [EMAIL PROTECTED] 
VOICE: (608) 261-5738  FAX 264-5932

Hardware, n.:
        The parts of a computer system that can be kicked.

_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to