From: Jim Weirich Date: 2005-11-15T11:58:00+09:00 Subject: Re: using n.times with gsub On Monday 14 November 2005 09:42 pm, davidpthomas@gmail.com wrote: > GOAL: one-liner substitute of 5 spaces at beginning of a line. > > WORKS: gsub(/^/, " ") > FAILS: gsub(/^/, 5.times {putc " "}) > > -example- > WORKS: $ cat foo.out | ruby -pe 'gsub(/^/, " ")' > FAILS: $ cat foo.out | ruby -pe 'gsub(/^/, 5.times{putc " "})' > > > I've tried variations of putc, puts, and print. All fail in different > ways. cat foo.out | ruby -pe 'gsub(/^/, " " * 5) cat foo.out | ruby -pe 'gsub(/^/, (1..5).collect { " " }.join } -- -- Jim Weirich jim@weirichhouse.org http://onestepback.org ----------------------------------------------------------------- "Beware of bugs in the above code; I have only proved it correct, not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)