Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: ASCII Rulers

by petral (Curate)
on Apr 03, 2001 at 15:47 UTC ( #69266=note: print w/ replies, xml ) Need Help??


in reply to ASCII Rulers

A couple of minor golfish things, without really changing the algorithm:

sub ruler { my $n = 9 + shift; chop $n; join "", " ", map(" "x(9-/../).$_, 1..$n), "\n", "0123456789" x $n, "0\n" }
But for filling exactly to (arg) columns (eg, to avoid wrapping when using $ENV{COLUMNS}):
sub ruler { my $n = shift; join"", " ", map(" "x(9-/../).$_, 1..$n/10), "\n", map(/.$/g, 0..$n), "\n" }
update: or (of course) ye olde one-liner:perl -lwe 'print" ",map(" "x(9-/../).$_,1..$ARGV[0]/10),"\n",map/.$/g,0..shift'
further update: chipmunk got it.  He's almost using printf as a map!

p


Comment on Re: ASCII Rulers
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://69266]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (11)
As of 2015-07-30 07:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (270 votes), past polls