[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

printing from a file - beginner

Johnathan Smith

12/4/2007 11:52:00 AM

hi there

im new to ruby and ive got a bit of a problem

basically i have a text file and i want my ruby class to perform a
regular expression to count the lines with a Tag in the text file

if anyone could offer any help or psuedo code id be very appreciative

my code is below
many thanks

text file:

Tag: ref1
Type: Book
Author: Little, S R

Tag: ref2
Type: Journal
Author: Smith, J

ruby code:

#
require 'getoptlong'

opts = GetoptLong.new(
['--style', '-n', GetoptLong::NO_ARGUMENT ],
['--database', '-i', GetoptLong::REQUIRED_ARGUMENT]
)
opts.each do |opt, arg|
case opt
when '--style'
require arg
when '--database'
end
end
#
#
#
# process options
#
#
#
File.open('reference.txt').each do |line|
# puts line
Regexp.new
end
#
#
--
Posted via http://www.ruby-....

1 Answer

Mark Woodward

12/4/2007 12:25:00 PM

0

On Tue, 4 Dec 2007 06:51:49 -0500
Johnathan Smith <stu_09@hotmail.com> wrote:

> hi there
>
> im new to ruby and ive got a bit of a problem

new to this myself so take that into consideration ;-)

>
> basically i have a text file and i want my ruby class to perform a
> regular expression to count the lines with a Tag in the text file
>
> if anyone could offer any help or psuedo code id be very appreciative
>
> my code is below
> many thanks
>
> text file:
>
> Tag: ref1
> Type: Book
> Author: Little, S R
>
> Tag: ref2
> Type: Journal
> Author: Smith, J
>
> ruby code:
>
> #
> require 'getoptlong'
>
> opts = GetoptLong.new(
> ['--style', '-n', GetoptLong::NO_ARGUMENT ],
> ['--database', '-i', GetoptLong::REQUIRED_ARGUMENT]
> )
> opts.each do |opt, arg|
> case opt
> when '--style'
> require arg
> when '--database'
> end
> end
> #
> #
> #
> # process options
> #
> #
> #

count = 0 (not sure I need that?)

> File.open('reference.txt').each do |line|
> # puts line
> Regexp.new

count += 1 if line =~ /^Tag:\s/
(not sure if I need to escape the ':' ie '\:')
> end
> #
> #


cheers,

--
Mark