From: jackster the jackle Date: 2008-09-28T10:03:43+09:00 Subject: Re: Trying to use gsub using variables thanks...I got that to work...now for my last question...I am trying to match on a hash value. I have a text file that gets opened with 4 different types of statements in it...the values are contained in my hash called "h". The values in the hash are (IN,OUT,PP,AA). @acl_list contains a bunch of firewall rules that either have the value IN,OUT,PP or AA in them. What I am trying to do is loop through @acl_list, substitute the value of h with the key (which works great) but then, I need to put the number 1 in the first firewall rule that contains IN, then the number 2 in the second firewall rule that contains IN etc. When I'm finished with the "IN" rules, I want to do the same thing for "OUT","PP" and "AA". What I have here works great but only for the "IN" rules: k= 1 @acl_list.each do |acl| h.each {|key,value| acl.gsub!(/#{key}/,value)} if acl[/IN/] acl.gsub!(/^/,k.to_s) k+=1 puts acl end What I really need is to match on the value of the hash, then add the numbers to the beginning of each line. I thought the following would work but it doen't (although #{value} does have the correct info in it). Can anyone help me figure out how I can get the loop to match on the value of my hash? I think if I can get this to work, everything will be the way I need it. k= 1 @acl_list.each do |acl| h.each {|key,value| acl.gsub!(/#{key}/,value)} if acl[/#{value}/] acl.gsub!(/^/,k.to_s) k+=1 puts acl end Thanks again! jackster Here's an example of what is actually contained in @acl_list: access-list IN permit tcp 172.2.1.0 255.255.0.0 172.1.1.0 255.255.255.0 eq ftp access-list IN permit tcp 10.1.1.0 255.255.0.0 172.1.10 255.255.255.0 eq 13782 access-list IN permit tcp 10.1.1.0 255.255.0.0 172.1.1.0 255.255.255.0 eq ftp access-list OUT permit tcp 10.1.1.0 255.255.0.0 172.1.1.0 255.255.255.0 eq ftp access-list OUT permit tcp 10.1.1.0 255.255.0.0 172.1.1.0 255.255.255.0 eq ftp access-list PP permit tcp 172.1.0.0 255.0.0.0 172.1.1.0 255.255.255.0 eq www access-list PP permit tcp 172.1.0.0 255.0.0.0 172.1.1.0 255.255.0.0 eq ftp access-list PP permit tcp 172.1.0.0 255.0.0.0 172.1.100.0 255.255.0.0 eq ssh access-list AA permit tcp 172.2.0.0 255.0.0.0 172.1.1.0 255.255.0.0 eq www access-list AA permit tcp 172.22.0.0 255.255.0.0 172.21.100.0 255.0.0.0 eq 8080 My end result is that I want these same rules to look like this: 1 access-list IN permit tcp 172.2.1.0 255.255.0.0 172.1.1.0 255.255.255.0 eq ftp 2 access-list IN permit tcp 10.1.1.0 255.255.0.0 172.1.10 255.255.255.0 eq 13782 3 access-list IN permit tcp 10.1.1.0 255.255.0.0 172.1.1.0 255.255.255.0 eq ftp 1 access-list OUT permit tcp 10.1.1.0 255.255.0.0 172.1.1.0 255.255.255.0 eq ftp 2 access-list OUT permit tcp 10.1.1.0 255.255.0.0 172.1.1.0 255.255.255.0 eq ftp 1 access-list PP permit tcp 172.1.0.0 255.0.0.0 172.1.1.0 255.255.255.0 eq www 2 access-list PP permit tcp 172.1.0.0 255.0.0.0 172.1.1.0 255.255.0.0 eq ftp 3 access-list PP permit tcp 172.1.0.0 255.0.0.0 172.1.100.0 255.255.0.0 eq ssh 1 access-list AA permit tcp 172.2.0.0 255.0.0.0 172.1.1.0 255.255.0.0 eq www 2 access-list AA permit tcp 172.22.0.0 255.255.0.0 172.21.1.0 255.0.0.0 eq www -- Posted via http://www.ruby-forum.com/.