[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Regexp challenge

Casimir P

5/23/2007 4:13:00 PM

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
6 Answers

Todd Benson

5/23/2007 4:40:00 PM

0

On 5/23/07, Casimir Pohjanraito <pikselNOSPAMMi@welnospmamho.com> wrote:
> 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.

James Gray

5/23/2007 4:42:00 PM

0

On May 23, 2007, at 11:14 AM, Casimir Pohjanraito wrote:

> 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

Tim Pease

5/23/2007 7:40:00 PM

0

On 5/23/07, James Edward Gray II <james@grayproductions.net> wrote:
> On May 23, 2007, at 11:14 AM, Casimir Pohjanraito wrote:
>
> > 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
>

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

TwP

James Gray

5/23/2007 7:42:00 PM

0

On May 23, 2007, at 2:39 PM, Tim Pease wrote:

> On 5/23/07, James Edward Gray II <james@grayproductions.net> wrote:
>> On May 23, 2007, at 11:14 AM, Casimir Pohjanraito wrote:
>>
>> > 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
>>
>
> 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

Tim Pease

5/23/2007 7:58:00 PM

0

On 5/23/07, James Edward Gray II <james@grayproductions.net> wrote:
>
> <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

Rick DeNatale

5/23/2007 8:54:00 PM

0

On 5/23/07, James Edward Gray II <james@grayproductions.net> wrote:

>
> <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>

--
Rick DeNatale

My blog on Ruby
http://talklikeaduck.denh...