I need to grab the last number in an integer produced from a loop. Right now, my loop is only going to 300. I want to grab just the right most digit in the integer. My current code:
perl -e 'for ( $dec = 0 ; $dec <= 300 ; $dec++ ) { $one =~ /\d+${1}$/;
+print "$dec -> $one\n"; }'
Desired Output
1 -> 1
2 -> 2
3 -> 3
.
.
.
45 -> 5
46 -> 6
47 -> 7
.
.
.
137 -> 7
138 -> 8
139 -> 9
140 -> 0
141 -> 1
etc etc
Special request
I appreciate all assistance I get from the monkage. However, if there is no way to get my desired output using an RE or that an RE is just plain not worth it I request you just let me know this without attempting to give me working code.
This will allow me to find an answer and I would like to find a different means on my own first so I can learn this language!! :) Right now, my wish is to do it with a working RE.
----------
- Jim
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.