http://www.perlmonks.org?node_id=69240

I found myself grovelling through some fixed-width data and I realised that what I needed was one of those funky ASCII rulers to help me count column widths, those things that look like:

1 2 3 4 5 012345678901234567890123456789012345678901234567890

I whipped up something quickly and it does the job, but it's pretty ugly and I'm sure someone can do better either more elegantly and/or in a more compact manner.

The constraints are simple: a sub takes a scalar arg representing the length of the ruler. This number is rounded up to the next multiple of 10. Return the string representing the ruler.

When you get to the hundreds (and I did need a ruler that was 240 wide) it should look like this:

11 12 13 14 15 ...478901234567890123456789012345678901234567890

Golf, anyone?

sub ruler { my($n,$r) = ($_[0], ' '); $r .= ' 'x(10-length).$_ for (1..($n+9)/10); return "$r\n" . '0123456789' x (($n+9)/10) . "0\n"; }