I have written a program that will intake a bunch of information from a user, and based on this will search some files for this information. I'm trying to make the code more robust, and be able to handle more errors. One error that I would like to fix, is if the user happens to input the wrong type of information. For instance, the user hits a letter when the code wants a number. I know perl will take the which ever input you give it, but I need to be able to differentiate between the two in order to perform other checks using comparisons. Any help would be appreicated, below is a sipit of my code that hopefully shows the issue a little.
print "\nPlease enter the start date for your search (mm/dd/yyyy hh:mm
+): ";
$date = <>;
chomp( $date );
@eDate = split( /\/| |:/, $date );
$sMonth = $eDate[0];
$sDay = $eDate[1];
$sYear = $eDate[2];
$sHour = $eDate[3];
$sMinute = $eDate[4];
#Verify the user enter all neccessary information
if( defined( $sMonth ) == 0 || defined( $sDay ) == 0 || define
+d( $sYear ) == 0 || defined( $sHour ) == 0 || defined( $sMinute ) ==
+0)
{
$skip = 1;
print "Please enter all required data fields.\n";
}
#Verify the month entered by the user.
if( $skip == 0 && $sMonth > 0 && $sMonth < 13 )
{
$correct = 1;
}
The second if block is where the incorrect data type error is being thrown.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.