search a date range in perl
So, disclaimer, I know zilch about perl. The script I have to use was originally written in perl. So, bear with me as I completely use the wrong terms!
I need to take a working script, but modify it to search starting at a certain date to today. Hours don't matter, just day/month/year. For example, starting march 10 2019 to today. How would I do this? Thanks! btw, the script is running on rhel 6.10 |
Quote:
If it was me, and I was getting a date from a user, I'd force a format of YYYY-MM-DD, and convert it to epoch time, and just get the date now in epoch time, and do the search. Again, you don't say what you're searching...a TIMESTAMP field in MySQL takes something different. Running a Linux 'find' command also needs something different. Short answer: you have lots of options which are easy to implement, but they're going to depend on where you get the input data, and how you use it. |
Here is the script, as it currently is:
Code:
#!/usr/bin/perl -w Essentially what is happening is the script uses an ldap connection to a banner database, which then creates a text file with a list of names/emails used for updating a listserv. |
thanks. Would be nice to use [code] tags to keep original formatting.
I have no any idea what are you (the script) searching for and especially what to do (what should be compared) with that time. |
To preserve formatting place your code snippets inside [CODE]...[/CODE] tags. You may type those yourself or click the "#" button in the edit controls.
There are no clues in your original question or the posted code as to what date you want to search for. Is it the timestamp of some files, or the content of some files, or lines in one file... we cannot tell from what you have posted. Please review the Site FAQ for guidance in posting your questions and general forum usage. Especially, read the link in that page, How To Ask Questions The Smart Way. The more effort you put into understanding your problem and framing your questions, the better others can help! |
So you're using Time::Piece and getting the current date for the report. Fine....so that gives you your 'date now'. And it looks like you're trying to look up someone in LDAP, and creating files, reading from other files, etc. But since we have NONE of those, we can't even run the code you've posted. And again, as asked, where is the date going to be coming FROM?? Is the user going to enter it/be prompted for it?? What is the actual GOAL of this script having a date-range and where is the date in what you're searching???
Nothing you've describe is particularly hard, and the fact you've already got the date module in, running, and getting one of the two dates means you're a good part of the way there. |
Ok, I have tried to preserve the format. I explained a bit more also in the same post. As for the time part, I want to be able to limit the time for results to filter out old results. I hope I have given helpful info.
|
Quote:
Quote:
|
Quote:
As has been asked, where is the other date coming from? What do you mean by "old results"? How will you filter them out? |
I am basically just trying to set a date range. It is currently taking everything up to today. What I want to do is to limit how far back it goes, i.e. 03/12/2019 to today.
A lot of the other info I just do not have since I have no access of the banner database, I can say people are entered in by "roles" such as staff, admin, ect. The ldap portion isn't really important is the script is just using it to access the db. The db compiles the list, which is then just outputted to a txt file. |
Quote:
Quote:
If you don't have the answers, we sure won't either. Just restating what you want to do over and over is pointless. If you don't know about Perl, how/why did you get handed this script and told to modify it? Who wrote this script to start with? |
Quote:
Set a variable to the starting date. Use the same syntax as for the $dateout variable. That is the beginning of your range. As has been said, you're not giving us anything at all to work with to help you. I can't see any place dates are used in that script except to define the location of a file. |
The start date was arbitrary, I just picked that date.
Would I put the $dateout variable before or after the current $dateout variable? I was given this mainly cause I drew the short straw. No one here does perl anymore. The person that wrote these has been gone probably 5 years, if not longer. I'm sorry I am not giving whatever info is being looked for. I'm not even sure what is desired. If you all think it is frustrating for you, imagine what it is like for me, when I don't even know perl terminology. I am giving you the info I know. The script itself is run from cli. It doesn't go through any sort of gui or webpage, just cli. The include/exclude is unimportant. The only thing that goes in those files are names to be either included or excluded from the output. As stated, the script already gives up to today's date. I just want to modify the script to do from X date, to today's date. If that is the $dateout variable, then I'll figure that out. If this info just isn't helpful for anything, I'll just figure out a different way to do what I need. I'm not trying to be difficult, I am just poor with understanding other peoples terminology. However, need help rebuilding a brushless motor? How about a 3-phase alternator or maybe using a flowbench to port a head? |
Quote:
Your new variable would have a different name...something like $datestart...I don't know the exact syntax for setting an arbitrary date using Time::Piece I'd have to read the documentation. Again, frankly, we don't see anywhere that the current date ($dateout) is used at all, except to define the directory in which the file newstudents.list is contained, so I can't see where knowing some arbitrary start date is going to help you do anything. What is your vision/expectation to be able to do with the date once you've got it? What are you trying to accomplish here? Only getting new(ish) records from the ldap? That would require modifying the query to the ldap. Do you know how to do that? |
This should give you something to play around with.
Code:
use strict; |
All times are GMT -5. The time now is 05:57 PM. |