in reply to scalar or sub that can tell me the terminal print offset ?
Not sure what you're actually looking for.
Would this fit the bill?
my @strings = ( 'Paint it black', 'Satisfaction', 'Lady Jane' ) ; say $_, ' ', length for @strings;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: scalar or sub that can tell me the terminal print offset ?
by palkia (Monk) on Mar 17, 2012 at 19:24 UTC | |
This is how I expect such a scalar (or sub) to work: 1. Say I print a 5 (normal) chars string, than the desired scalar will have a increase in value of 5. 2. when in the beginning of a line it will be zero. 3. after a print of \n or \r, reset to zero. 4. after a print of \t, increase value to the next multiple of 8. 5. after a print of \b, decrease value by 1. 6. after a print of \a, no change in value. 7. modulus: every time it gets over 80 it is reduced by 80 (after 80 chars there's a new line). Probably some other rules too. I can figure these out, so I can write it (probably), but I find it hard to believe this doesn't already exists. | [reply] |
by LanX (Saint) on Mar 17, 2012 at 19:34 UTC | |
most probably this is just an xy problem. i.e. you are trying to solve a problem in a wrong way. I slightly remember a BASIC dialect which had such a feature to allow positioning the cursor, but in Perl I never missed this. IMHO in reality you'd rather prefer using | [reply] [d/l] |
by Not_a_Number (Prior) on Mar 17, 2012 at 19:51 UTC | |
I must agree with LanX that you probably have an XY Problem. Have you considered Text::Wrap? | [reply] |
by ww (Archbishop) on Mar 17, 2012 at 20:50 UTC | |
"Text::Wrap" should be fairly easy to modify to suit your rules -- once you've decided what all of them are. But if you're a glutton for punishment, you could modify this exercise (which dates back several years and is rather fragile -- tabs in the data, for example, would break the formatting for the lines in which they appeared) -- likely by outputting the $chars to another string, and reporting its len. Output:
But plaudits to those others who also suspect an XY problem, too, as what you've specced so far, seems somewhat removed from real-world relevance. Or, is this homework? If so, say so, because you learn very little about programming if you hand in one of our solutions. | [reply] [d/l] [select] |