http://www.perlmonks.org?node_id=514402


in reply to array processing

Use a hash. Something like the following

# opening of files etc. my %users = (); while ($line = <errlog>) { chomp $line; next unless ($line =~ /Login succeeded/); $users{(split / /, $line)[6]} ||= 1; } foreach (sort keys %users) { print LOGINF $_, "\n"; } # closing fhs etc
This is untested.

NB: consider using lexical filehandles.

hth,

regards,
tomte


An intellectual is someone whose mind watches itself.
-- Albert Camus

Replies are listed 'Best First'.
Re^2: array processing
by inman (Curate) on Dec 06, 2005 at 11:34 UTC
    I preferred a regex over a split since we are only getting the user out of the data and we don't need any of the other values. You can increment the user's login count in one line inside the while loop:
    $users{$1}++ if $line =~ /Login succeeded. User: (\w+)/i;