From: "David A. Black" Date: 2005-11-15T12:26:34+09:00 Subject: Re: using n.times with gsub Hi -- On Tue, 15 Nov 2005, Ara.T.Howard wrote: > On Tue, 15 Nov 2005 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. >> >> thoughts? -- dave > > works: > > harp:~ > cat a > a > b > c > harp:~ > ruby -pe ' 5.times{ gsub /^/, 32.chr } ' < a > a > b > c > > simpler: > > harp:~ > ruby -pe ' sub /^/, 32.chr * 5' < a > a > b > c Tiny further simplification: s/