in reply to Re^2: What is wrong with this code?
in thread What is wrong with this code?
Glad you picked up on the use of 'elsif'. Used properly, it's a very powerful tool and you used it correctly. It can help you find all possible combinations that are acceptable ( just like you did ).
Now this is my preference, since I do a lot of web cgi programming, is to not overuse the 'die' function. You used it correctly, but I prefer to have a 'sub DieRtn{}' that is called in a error situation. This routine can determine the severity of the error and provide a way to recover. Once you 'die', it's not easy to recover.
And if this was a cgi script, the 'die' error would just be shown on the browser window. This wouldn't be very friendly, when a simple "I don't understand. . ." would allow the user to try it again.
Now look at this from your user's (brother) point of view. He has to type in the command and then type the shape and then the size(s) and then he sees "I do not ...". What you want as the designer/programmer of this script is for him to use this as much as possible. That was the purpose of the loop:
Now you have a clean exit to the program and you have reduced the typing for your end-user. If this is for a typing class and not a math class, then testing his typing skills would be a good thing.while ( 1 ) ## You may prefer while ( 1==1 ) { Do your stuff . . . elsif ( $type eq '' ) { last; } else { ... notify of input not correct and show what's acceptable . + . . } }
Keep up the good work...Ed
"Well done is better than well said." - Benjamin Franklin
|
|---|