Most likely your basic problem is if ( $stamp < $t ) { which finds the oldest login time for each user.

A somewhat cleaned up test version of your code that doesn't require external files is offered below:

use strict; use warnings; my $search='\bconnected, address\b' ; my @users = qw(name1 name2); my %R; print "search: @users\n"; while (<DATA>) { next unless /$search/o; s/L /:/; s/<.*>//; s/$search//o; s/ - /-/; my ($time, $name, $addy) = split; my $cleanName = name_match ($name); next unless $cleanName; my $nTime = fix_time ($time); my $rec = "$nTime $time $name"; if (! exists $R{$cleanName}) { $R{$cleanName} = $rec; next; } my ($t) = $R{$cleanName} =~ /^(\d+)/; $R{$cleanName} = $rec if $nTime > $t; } print "--------------------------\n"; my @values = sort values %R; foreach my $v (@values) { print STDOUT (split /:/, $v, 2)[1]; print "\n"; } # compare names, log names may have attributes; like sub name_match { my $cleanName = shift; $cleanName =~ tr/"//d; foreach my $user (@users) { return $user if $cleanName =~ /$user/; } return ""; } # convert time from 'L: MM/DD/YYYY - hh:mm:ss' to YYYYMMDDhhmmss # which makes time comparison a doddle sub fix_time { local $_ = shift; s/.//; tr/://d; my($date, $time) = split /-/; my ($m, $d, $y) = split "/", $date; return "$y$m$d$time"; } __DATA__ L 03/30/2006 - 11:59:17: "name1" connected, address "192.168.1.1:27005 +" L 03/30/2006 - 11:59:18: "name3" connected, address "192.168.1.1:27005 +" L 03/30/2006 - 12:29:17: "name2" connected, address "192.168.1.1:27005 +" L 03/30/2006 - 12:30:17: "name1" connected, address "192.168.1.1:27005 +" L 03/30/2006 - 12:45:17: "name4" connected, address "192.168.1.1:27005 +"

Prints:

search: name1 name2 -------------------------- 03/30/2006-12:29:17: "name2" 03/30/2006-12:30:17: "name1"

DWIM is Perl's answer to Gödel

In reply to Re: A pretty simple perl script.. by GrandFather
in thread A pretty simple perl script.. by xnd

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.