Beefy Boxes and Bandwidth Generously Provided by pair Networks Frank
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: array processing

by Tomte (Priest)
on Dec 06, 2005 at 11:04 UTC ( #514402=note: print w/ replies, xml ) Need Help??


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


Comment on Re: array processing
Download Code
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;

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://514402]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (10)
As of 2014-04-21 16:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (498 votes), past polls