<rant volume="low">
Folks, this node is a good example of how we often take a vague statement of requirements and jump right in to solutions before we're clear on the problem that we're trying to solve. (I'm guilty here, too.)
Take a moment to look at the problem statement we were given to work with. Does it warrant the solutions that have been proposed, or might it be more appropriate to get clarifications before proceeding to code.
Here's what we were given to work with:
- Find the length of a string.
- Remove the last two characters from the string.
- Save the remaining character to a variable.
We can drop item 1) as being a non-requirement. It's really one step towards a possible implementation of 2)
Next we're given an example:
If I had the following strings: "1ST", "21ST" and "101ST", I would like to remove the "ST" and retain the numbers.
At this point we should stand back and ask:
- Will all input be leading digits plus a two character suffix?
- Will the suffix always be "ST"? What about "st"? What about "TH"?
- What should we do with input that isn't leading digits plus a two character suffix?
Only after we get answers to theses are we really in a position to start suggesting implementations. To do otherwise risks having the problem come back to us
n more times, each time revealing a new requirement that our solution didn't satisfy.
</rant>
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.