[#6363] Re: rescue clause affecting IO loop behavior — ts <decoux@...>

>>>>> "D" == David Alan Black <dblack@candle.superlink.net> writes:

17 messages 2000/11/14
[#6367] Re: rescue clause affecting IO loop behavior — David Alan Black <dblack@...> 2000/11/14

Hello again --

[#6582] best way to interleaf arrays? — David Alan Black <dblack@...>

Hello --

15 messages 2000/11/26

[#6646] RE: Array Intersect (&) question — Aleksi Niemel<aleksi.niemela@...>

Ross asked something about widely known and largely ignored language (on

23 messages 2000/11/29
[#6652] RE: Array Intersect (&) question — rpmohn@... (Ross Mohn) 2000/11/29

aleksi.niemela@cinnober.com (Aleksi Niemel) wrote in

[#6723] Re: Array Intersect (&) question — Mathieu Bouchard <matju@...> 2000/12/01

> >Use a hash. Here's code to do both and more. It assumes that

[#6656] printing/accessing arrays and hashes — raja@... (Raja S.)

I'm coming to Ruby with a Python & Common Lisp background.

24 messages 2000/11/30

[ruby-talk:6438] variable in regular expression

From: markus jais <mjais@...>
Date: 2000-11-18 16:41:40 UTC
List: ruby-talk #6438
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 






In This Thread

Prev Next