2009/2/19 RichardOnRails <RichardDummyMailbox58407 / uscomputergurus.com>:
> I'm trying to use Ruby REs to transform Windows addresses into HTML
> anchors.
>
> CODE:
> DEBUG = 1
> fo= File.open("Microsoft EXEs xformed.txt", "w")
> fi= File.new("Microsoft EXEs.txt")
> fi.each { |line|
...
> }
> fi.close
> fo.close

I suggest rewriting this as

File.open "Microsoft EXEs.txt" do |fi|
  File.open "Microsoft EXEs xformed.txt", "w" do |fo|
    fi.each ...
  end
end

First, the block form of File.open is much safer because then file
handles will *always* be closed which is not the case for your
version.

Second, do the less dangerous operation first, because if that fails
you do not accidentally overwrite file "Microsoft EXEs xformed.txt".

Cheers

robert

-- 
remember.guy do |as, often| as.you_can - without end