Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Memo to self.

Reply
Thread Tools

Memo to self.

 
 
John Carter
Guest
Posts: n/a
 
      02-20-2006
Never under estimate what you can achieve with
IO.read( "filename").scan(%r{}mx) do |match|
end

Especial as you can control how greedy the regex is with .*?

I just deleted a lot of code and replaced it with one line.

John Carter Phone : (64)(3) 358 6639
Tait Electronics Fax : (64)(3) 359 4632
PO Box 1645 Christchurch Email : http://www.velocityreviews.com/forums/(E-Mail Removed)
New Zealand

Carter's Clarification of Murphy's Law.

"Things only ever go right so that they may go more spectacularly wrong later."

From this principle, all of life and physics may be deduced.


 
Reply With Quote
 
 
 
 
Hal Fulton
Guest
Posts: n/a
 
      02-20-2006
John Carter wrote:
> Never under estimate what you can achieve with
> IO.read( "filename").scan(%r{}mx) do |match|
> end
>
> Especial as you can control how greedy the regex is with .*?
>
> I just deleted a lot of code and replaced it with one line.


Well, as your self.memo included the rest of us, how about
sharing the example?


Hal



 
Reply With Quote
 
 
 
 
William James
Guest
Posts: n/a
 
      02-20-2006
John Carter wrote:
> Never under estimate what you can achieve with
> IO.read( "filename").scan(%r{}mx) do |match|
> end
>
> Especial as you can control how greedy the regex is with .*?
>
> I just deleted a lot of code and replaced it with one line.
>
> John Carter Phone : (64)(3) 358 6639
> Tait Electronics Fax : (64)(3) 359 4632
> PO Box 1645 Christchurch Email : (E-Mail Removed)
> New Zealand
>
> Carter's Clarification of Murphy's Law.
>
> "Things only ever go right so that they may go more spectacularly wrong later."
>
> From this principle, all of life and physics may be deduced.


# Read and parse the first file on the command line.
gets(nil).scan( //mx ) { |s|
}
# Read and parse the rest of the files.
ARGF.read.scan( //mx ) { |s|
}

 
Reply With Quote
 
John Carter
Guest
Posts: n/a
 
      02-23-2006
On Mon, 20 Feb 2006, Hal Fulton wrote:

> John Carter wrote:
>> Never under estimate what you can achieve with
>> IO.read( "filename").scan(%r{}mx) do |match|
>> end
>>
>> Especial as you can control how greedy the regex is with .*?
>>
>> I just deleted a lot of code and replaced it with one line.

>
> Well, as your self.memo included the rest of us, how about
> sharing the example?


Ok. Just quickly. I had a file of the format...

blah
blah
Command :
some stuff
some more stuff I \
want with line continuation \
characters

blah
blah
Command :
more some stuff
more some more stuff I \
want with line continuation \
characters

blah
blah
...

that I wanted transformed into
some stuff
some more stuff I want with line continuation characters
more some stuff
more some more stuff I want with line continuation characters


So I started write a routine to fix up the \ characters yield fixed
lines and then a state machine to search for 'Command:' and gather
everything until the blank line and then skip until...

I start playing with Generator since I realised I could then keep
everything in a
each_something do |thing|
yield other_thing( thing)
end
pattern instead of doing state machines and then I threw everything away
and replaced it with..

File.read( "big_file").scan(%r{\nCommand\ :\n(.*?)\n\n}mx) do |command|
puts $1.gsub( %r{\\\n}mx, '')
end

and then
everyone.send( :memo, "to self")

John Carter Phone : (64)(3) 358 6639
Tait Electronics Fax : (64)(3) 359 4632
PO Box 1645 Christchurch Email : (E-Mail Removed)
New Zealand

Carter's Clarification of Murphy's Law.

"Things only ever go right so that they may go more spectacularly wrong later."

From this principle, all of life and physics may be deduced.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Update Access Memo field from ASP.NET =?Utf-8?B?TWF0dA==?= ASP .Net 6 04-11-2005 01:22 PM
Re: OFF-T Did I miss the memo. HeartBreak Kid Hornet© Version 1 Computer Support 0 01-24-2005 09:06 PM
Display Memo Text Gmansky ASP .Net 2 06-28-2004 03:12 AM
Free Online VHDL MEMO Amontec, Laurent Gauch VHDL 0 05-24-2004 10:38 AM
SUN Java memo Developwebsites Java 3 11-13-2003 09:51 AM



Advertisments