Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: How to build a better mousetrap (or a variable to hold a column-measuring scale)

by Paladin (Vicar)
on Sep 09, 2019 at 20:52 UTC ( [id://11105909] : note . print w/replies, xml ) Need Help??


in reply to How to build a better mousetrap (or a variable to hold a column-measuring scale)

How about something like:
#!/usr/bin/perl use strict; use warnings; my $len = $ARGV[0]; my $cur = 10; print "|---+----"; while ($cur < $len) { my $prn = $cur % 100 ? $cur % 100 : $cur; my $sep = substr "|----+----", length($prn); print $prn, $sep; $cur += 10; } print "|\n";
No hardcoded numbers at all. Call it with prog.pl <length>:
~/tmp$ perl ruler.pl 50
|---+----10---+----20---+----30---+----40---+----|
~/tmp$ perl ruler.pl 140
|---+----10---+----20---+----30---+----40---+----50---+----60---+----70---+----80---+----90---+----100--+----10---+----20---+----30---+----|