From: Clement Ow Date: 2008-05-15T16:45:52+09:00 Subject: Re: Handling of arrays Clement Ow wrote: >> Oh yea, i did try this but it doesnt work, somehow *scratches head* It >> just shows all files to be moved, and it obviously did not carry out the >> exceptions. But if it's done this way, there wont be any point in keying >> in the various different exceptions alr, hence i got stuck. :/ > > Oh i realise what was wrong in the matching of this regexp, because in: >>files = exceptions_by_path[path].inject(Dir.glob("#{path}/*")) >>{|result, >>ex| result.reject{|x| x =~ Regexp.new(ex)}} >>end I found what is actually goin on in this statement. because x is the whole path name eg. //sins1234/home/file_name the regexp, /\A2007/ doesnt match the beginning of the string. And also the exceptions array must have "\\A2007" when passing it into Regexp.new. So my code now looks like this: >>>src1 = $file_exception[i].inject(Dir.glob(src)) {|result, ex|result.reject >>>{|x| File.basename(x) =~ Regexp.new(ex, Regexp::IGNORECASE)}} >>>Dir.glob(src1).each do |file| >>> #do sth >>>end > After much playing around with this statement,result here is the whole > path name, which apparently doesnt match the filename itself, hence > making /\A2007/ not able to work. (prolly need to use > File.basename(result)) But can you do me a favour by explaining what > this statement means as I dunno how come some variables assigned to > certain commands etc.? Thanks! However, for education sake, do u mind explaining how the whole inject statement works? thanks! ;) -- Posted via http://www.ruby-forum.com/.