From: Nate Wiger Date: 2006-10-21T06:57:08+09:00 Subject: Re: Easy way to check is sub!() succeeds? Gavin Kistner wrote: >> But sub! always returns nil, even when it succeeds (in Perl, it will >> return the number of substitutions made, enabling "next if >> s/\.$suf$//") > > Er, no it doesn't. > > irb(main):001:0> s="aaabbb" > => "aaabbb" > irb(main):002:0> s.sub!(/a+/,'') > => "bbb" > irb(main):003:0> s.sub!(/zzz/,'') > => nil Ok, that makes more sense. Turns out I was upsetting Ruby's scoping/aliasing. Eventually I got an error "Can't modify frozen string", which tipped me off. Now I have: ARGV.each do |file| path = file.dup # copy to tweak zip.each do |suf, cmd| if path.sub!(%r{\.#{suf}$}, '') And everything works ok. Seems like a loop w/i a loop thing? Anyways, thanks for the sub!() ptr. -Nate