From: "meinrad.recheis" Date: 2003-08-07T23:45:52+09:00 Subject: Re: Elegant solution for a loop-break problem raising an Exception is an excellent way of escaping nested loops. - mr On Thu, 7 Aug 2003 23:17:13 +0900, KONTRA Gergely wrote: > Hi! > > I've tried to write a little program, which detect duplicate files. > My way to solve this is to have a hash for the known files like this > { fileSize => [[file1,file2],[file3,file4]], > fileSize2 => [[file6,file7]] } > > So, file1..file4 have the same size, file1 and file2's content is > identical, similarly file3 and file4 is identical. > > First, the Hash is empty, and then I insert the files to be examined, > like this. > > files = Hash.new { [] } > for filename in filesToBeAdded > filesize=File.filesize(filename) > for fn in filename[filesize] > if equalContent(fn[0], filename) > # add this file to this 'segment' TODO: alter files > # next 'filename in filesToBeAdded' > end > end > # if loop exited normally, create a new segment > end > > So questions in general: > How can I alter items in a hash nicely? > Can I exit more loops with next/last/redo? (like in perl) > Is there something similar to python's for .. else ... structure? (Do > something, ONLY when the loop is terminated normally (without break) > > thx > Gergo