Regexp challenge

  • Thread starter Casimir Pohjanraito
  • Start date
C

Casimir Pohjanraito

Just out of curiosity, for fun:

Whats the rubyest ruby program you can code for opening a directory of
files and replacing a particular string in all files (if found) with
another string?

Lets suppose that all files in directory are text and the string to search
for is "target", and replace string is "practice".

Csmr
 
T

Todd Benson

Just out of curiosity, for fun:

Whats the rubyest ruby program you can code for opening a directory of
files and replacing a particular string in all files (if found) with
another string?

Lets suppose that all files in directory are text and the string to search
for is "target", and replace string is "practice".

Csmr

You go first.
 
J

James Edward Gray II

Whats the rubyest ruby program you can code for opening a directory of
files and replacing a particular string in all files (if found) with
another string?

Lets suppose that all files in directory are text and the string to
search
for is "target", and replace string is "practice".

From inside the directory in question:

$ ruby -pi -e 'gsub("target", "practice")' *

James Edward Gray II
 
T

Tim Pease

From inside the directory in question:

$ ruby -pi -e 'gsub("target", "practice")' *

James Edward Gray II

And we have a winner! James you never cease to amaze me. I just
learned three new things.

TwP
 
J

James Edward Gray II

And we have a winner! James you never cease to amaze me. I just
learned three new things.

<laughs> I come from Perl where tricks like that our very common,
which is probably just proof that my solution fails "the rubyest
ruby" requirement of the question.

James Edward Gray II
 
T

Tim Pease

<laughs> I come from Perl where tricks like that our very common,
which is probably just proof that my solution fails "the rubyest
ruby" requirement of the question.

Well, you did fail to use a regular expression ;)

TwP
 
R

Rick DeNatale

<laughs> I come from Perl where tricks like that our very common,
which is probably just proof that my solution fails "the rubyest
ruby" requirement of the question.

Well, I was tempted to comment that your solution seemed more perlish
than rubyish, but it was against my better nature. <G>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top