Break up your Choice logic so that it calls subroutines that do the actual work. It will make your code easier to understand if you do this,
$userInput = <STDIN>;
chomp $userInput;
$userInput = uc $userInput;
# you could probably do this on the STDIN, but I am not sure.
# Another monk should be able to tell you.
( $userInput eq 'L' or $userInput eq 'LIST' ) ? list_phone_book()
: ( $userInput eq 'A' or $userInput eq 'ADD' ) ? add_to_phone_book
+()
: ( $userInput eq 'D' or $userInput eq 'DELETE') ? delete_from_phone
+_book()
: ( $userInput eq 'Q' or $userInput eq 'QUIT' ) ? quit_phone_book()
: unknown_selection
+();
As it stands now, you would have read your whole script line by line to figure out where you are going for your selections. With the above code, you know where to look for each selection and what it is supposed to do.
You are also doing a bunch of open and closes all over the place, I beat your could get rid of a bunch of code by breaking those down in subroutines.
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.