Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
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 ( #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---+----|
  • Comment on Re: How to build a better mousetrap (or a variable to hold a column-measuring scale)
  • Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2020-02-24 20:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What numbers are you going to focus on primarily in 2020?










    Results (107 votes). Check out past polls.

    Notices?