|Perl Monk, Perl Meditation|
Re: Grep logs by start date and end date in different directoriesby Discipulus (Monsignor)
|on Jan 03, 2018 at 09:02 UTC||Need Help??|
Hello and welcome to the wonderful world of Perl!
as general advice avoid to shell out if Perl lets you to do something in it's own way: search afoken's threads about shell to know why and how.
Anyway if you need to build up such list of directories the better, imho, approach is looping different time values going backward. consider the following little snippet:
With such strings then build up the full path you need then use glob to build up a list of files and finally open them to search your wanted IPs.
If you organize this using subroutines all will be clean and wise! You can the add GetOpt::Long to admit a --foreward option to process in reverse order directories, just @dirs_date = reverse @dirs_date;
If you avoid the shell you can generalize the program to search not only IPs but whatever you want letting the user to enter a custom regex possibly passed in command line as argument.
PS consider to sign in to the monastery!
There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.