Then that someone ignored the instructions, unless there is a universe where time runs backwards (Red Dwarf not withstanding;), hence Garbage In, Garbage Out.
The point is that if you want to allow for the possiblity that someone using the program doesn't understand the difference between "Enter start date" and "Enter end date", and you wish to have the program perform remedial action, then that is your perrogative, but the last thing you need to do is mess with the while loop.
Simply add
die 'Dont be silly' unless Date_Cmp( $start, $end ) < 0;
after the input.
Of course, they could also type ^C at the first prompt and they fail to get the correct output. Is that the programs fault?
Or they might redirect the output to the nul device. Should the program attempt to trap and handle that situation?
Don't think I'm getting on your case, but the code was offered as how I would code it, as requested in the original post. If you or the OP, or anyone else wish to use it as is, that's fine. If you wish to add additional error checking to cater for the potential idiot user, that's fine too. You entirely welcome to ignore the code completely too.
Again, that tirade isn't aimed at you personally, but is a general comment against third-party, hyper-pedantic critisism and "corrections" of code offered by a 2nd party to a first party with the sole intent of being of assistance to the 1st party.
The keyword in that legalistic gobbaldy gook is "assistance". Code posted here is intended to be of assistance, an example, a pointer in (hopefully a right) direction. As such, it comes without warrenty or support and should be viewed and used in that light.
The expectation that the code will be 100% perfect, tailored exactly to the OP's needs, environment or skill levels is not just optimistic, it is dangerous. If that expectation is allowed to take hold, grow and flourish, then this site would die. Who would bother to spend their personal time trying to produce such code for no reward beyond "Personal satisfaction + XP", which in my opinion is worth just a little less than personal satisfaction alone.
Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
Hooray!
Wanted!
|