in reply to Re^3: Undefined Error
in thread Undefined Error

Well, I want to print "bad User" if count is greater than 3, that is the only output I want.
print "\t=> Bad user!\n" if @{$searches{$conn}} > 3;

Replies are listed 'Best First'.
Re^5: Undefined Error
by hdb (Monsignor) on Jun 15, 2013 at 14:05 UTC

    In your dataset, there is no one with more than 3 searches. If you do not like the other output, remove the print statements. If you want to check for the total number of searches, you need to sum up across connections like this:

    for my $user (keys %users) { my $totalsearches=0; for my $conn (@{$users{$user}}) { if( exists $searches{$conn} ) { print "User $user had ".scalar( @{$searches{$conn}} )." searches + on connection $conn\n"; $totalsearches += @{$searches{$conn}}; } } print "User $user had $totalsearches searches in total\n"; print "\t=> Bad user!\n" if $totalsearches > 3; }
Re^5: Undefined Error
by poj (Abbot) on Jun 15, 2013 at 14:29 UTC
    If you only want a total count the code can be simplified ;
    use strict; use warnings; my %users; my %conn; while (<DATA>) { # I use DATA handle instead of $fh for convenience if( /BIND/ ) { my( $conn, $uid ) = /conn=(\d+).*uid=(.*?),/; $conn{$conn} = $uid; } if( /SRCH=Q/ ) { my ($timestamp, $conn) = /\[(.*?)\] conn=(\d+)/; my $uid = $conn{$conn}; ++$users{$uid}; } } for my $uid (keys %users) { my $count = $users{$uid}; print "\t=> Bad user $uid ! count = $count\n" if $count>3; }
    poj