Use a do...for loop.
my $calog = "/var/log/ca/ca.log.1"; my @newlist; @calines = get_file($calog); @newlist = which_lines(@calines); print "@newlist"; ############################# # Important part ############################# sub which_lines { for (@_) { /\.512/ && do { push(@new1, $_);}; } for (@new1) { !/renewed|revoked/ && do { push(@new, $_); }; } return @new ; } sub get_file { my $file = shift; local *IN; open (IN, "<$file") or die "Cannot read '$file': $!"; if (wantarray) { return <IN>; } else { return join '', <IN>; } }
This gives me the following output:
Sep 14 14:00:04 nt-na-pk NA(Domain-ca): Certificate came 'tuser.512' a +dded to database. Sep 14 14:48:20 nt-na-pk NA(Domain-ca): Certificate came 'psmith.512' +added to database.
It could be tidied up some, but you should get the idea....
Update:
After I posted this I re-read the problem, and this obviously doesn't work. You can change the /\.512/ to /\.512|\.2048/, and that takes care of the first problem I noticed.
Now, you say users that have not been removed or revoked? Does this need to go chronologically? If not, parse the remaining good lines for your user names, and then re-search the original array for lines where they have been revoked or renewed.
In the example of tuser.512, the renew line is directly after the good line. So in the case of chronological order, your logic flow could work: Get "added" line -> search next line for revoked|removed for same user.
~Hammy
In reply to Re: Need help with Parsing Unique Users out of Syslog
by HamNRye
in thread Need help with Parsing Unique Users out of Syslog
by dru145
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |