From: markus jais Date: 2000-11-19T01:41:40+09:00 Subject: [ruby-talk:6438] variable in regular expression hello, I have recently bought the new book about ruby and are new trying to learn. I have one question about variable in regular expressions I have a little script which I want to use to rename files in a directory: the code is a follows: old = ARGV[1] new = ARGV[2] dir = Dir.new("."); while line = dir.read next if line == "." or line == ".." puts line line.sub!(/old/, new) #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Error puts line end in the line with "line.sub" there is an error. I want to use the values in the variable "old" and "new" in this method, but I can not figure out how to to so. In Perl is goes like this: $old = $ARGV[0]; $new = $ARGV[1]; opendir(DIR, "."); while(defined ($line = readdir(DIR))) { next if $line eq "." or $line eq ".."; print "$line\n"; $line =~ s/$old/$new/; print "$line\n"; } here I just put a "$"-sign in front of the variables and the regex-parser interpolates the variable. can anyone tell me, how to do this in ruby???? thanks a lot markus