From: Robert Klemme Date: 2008-02-14T18:34:39+09:00 Subject: Re: my noob "numbering lines" programe. How to improve? 2008/2/14, Phrogz : > On Feb 13, 3:50 pm, Adam Akhtar wrote: > > Give us hints on how to improve this program. If you want to show your > > code off then go ahead but please give us the hints first i.e. what > > methods you would use, what you would rewrite in my code etc. Its so > > much better for me to go away and try and replicate your thinking than > > just reading it. > > > Here are some suggestions: > * Use the += and *= compound assignment operators > * Use << instead of .write > * "%10s" % str is like rjust, so > * "%#{numdigits}s %s" % [ linenumber, input ] Or rather "%*d %s" % [numdigits, linenumber, input ] printf "%*d %s", numdigits, linenumber, input > * Look at each_with_index > * Think about a better way to calculate numdigits; e.g.: > * Math.log10( max ).ceil > * total_lines.to_s.size * Look at ARGF and ARFG.lineno Kind regards robert -- use.inject do |as, often| as.you_can - without end