in reply to What is wrong with this code?
Everyone has helped you with the technical problems of your script, but you should think about the usefulness of helping your brother(end user) use the script. Just think how annoying it is to type 'CIRCE' by accident, and nothing happens!
Use perl to help the typist, such as:
This is untested code, so I'll leave the debugging to you. I have introduced some new functions, but the idea is to build a framework for your future work. You could add a hash or array of types. You could make each call a separate subroutine, add HTML and this could be the start of a cgi script for your web server. But best of all you have a framework for you and your brother to control your environment with perl. Maybe your brother's class mates would like to use your program and expand on it. Put a copyright on it, and now you're an author.my $help = qq|I am an area calculator that can do the following:\n \t 1 - Square \t 2- Rectangle\n \t 3 - Paralellogram \t 4 - Trapezoid\n|; ## Add additional fu +nctions here! print "\n\n$help\n"; while ( 1 ) { print "What would you like to do? "; my $type=<>; chomp ($type); $type = lc($type); while ($type) { if ( ($type eq '1' )||( $type eq 'square') ) { $type = "Square"; say "Okay. I am working with a $type.\n"; say "ENTER SIDE LENGTH"; my $square_side = chomp(<>); my $square_area= $square_side**2; say "ANSWER= $square_area"; } elsif ( ($type eq '2' )||( $type eq 'rectangle') ) { $type = "rectangle"; # etc. . . } elsif ( $type eq '' ) { last; } else { print "\n\n$help\n"; } } } print "Thank you for using my Calculator\n";
Learning perl now, will enable you to do and control customized things for the rest of your life.
Personally, I like that you found a real problem (your brother's learning) and you are solving it yourself.
Good start!
"Well done is better than well said." - Benjamin Franklin
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: What is wrong with this code?
by perl.j (Pilgrim) on Jul 24, 2011 at 16:00 UTC | |
by flexvault (Monsignor) on Jul 24, 2011 at 18:54 UTC |