PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.ruby > printing from a file - beginner
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
printing from a file - beginner

Réponse
 
LinkBack Outils de la discussion
Vieux 04/12/2007, 11h51   #1
Johnathan Smith
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut printing from a file - beginner

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 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-forum.com/.

  Réponse avec citation
Vieux 04/12/2007, 12h25   #2
Mark Woodward
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: printing from a file - beginner

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

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 07h25.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,09583 seconds with 10 queries