In article <irJj9.27338$32.485317 / weber.videotron.net>, Vincent Foley wrote:

> Ruby (that code has a serious bug though, see my thread, about
> String#gsub!):
 

> [code]
> #!/usr/bin/env ruby
> 
> wordList = open('/home/vince/fr_dict.txt', 'r').read.split('\n')
> repl = {
>     '_'   => '[a-',
>     '(v)' => '[aou]', 
>     '(c)' => '[bcdfghjklmnpqrstvwxyz]',
>     '(e)' => '['
> }    
> 
> while true
>   print '> '
>   reg = gets.chomp
>   repl.each_key { |token|
>     reg.gsub!(token, repl[token])
>   }
>   reg = '^' << reg << '$'
>   puts reg
>   for word in wordList
>     puts word if word =~ reg
>   end
> end
> [/code]

You seem to be mixing up Strings and Regexps, here I have made the keys
to repl Regexps and made reg a real Regexp.  Does this do what you want?

#!/usr/bin/env ruby
  
repl = {
    /_/     => '[a-',
    /\(v\)/ => '[aou]',
    /\(c\)/ => '[bcdfghjklmnpqrstvwxyz]',
    /\(e\)/ => '['
}

loop do
    print '> '
    reg = gets.chomp
    repl.each_key { |token|
        reg.gsub!(token, repl[token])
    }
    reg = /^#{reg}$/
    puts reg

    # file content match against reg removed...

end


> There ya go.  If you ahve any information about why I have that bug in
> the Ruby version, please let met know ASAP ;)  

Ruby seems to work fine ;-)  It is not the same as Python...

Hope this helps,

Mike

-- 
mike / stok.co.uk                    |           The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/       | GPG PGP Key      1024D/059913DA 
mike / exegenix.com                  | Fingerprint      0570 71CD 6790 7C28 3D60
http://www.exegenix.com/           |                  75D2 9EC4 C1C0 0599 13DA