J
Johnathan Smith
Hi
iv started writing a class which reads the data from a text file and
counts the number of Tags
however im having a struggle as I want to split the tag and the data
into a hash i.e the Tag is the index and the data is the rest
if anyone could provide me with any psuedo code i'd 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
Tag: ref3
Type: Conference Paper
Author: Williams, M
Tag: ref4
Type: Book
Author: Jones, M B
ruby class:
#!/usr/local/bin/ruby
#
#
#
require 'getoptlong'
opts = GetoptLong.new(
['--style', '-n', GetoptLong::NO_ARGUMENT ],
['--database', '-i', GetoptLong::REQUIRED_ARGUMENT]
)
$linecount = 0
opts.each do |opt, arg|
case opt
when '--style'
require arg
when '--database'
end
end
#
#
#
# process options
#
#
#
File.open('reference.txt').each do |line|
if line =~ /^tag:/i
$linecount += 1
end
end
puts $linecount
#
iv started writing a class which reads the data from a text file and
counts the number of Tags
however im having a struggle as I want to split the tag and the data
into a hash i.e the Tag is the index and the data is the rest
if anyone could provide me with any psuedo code i'd 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
Tag: ref3
Type: Conference Paper
Author: Williams, M
Tag: ref4
Type: Book
Author: Jones, M B
ruby class:
#!/usr/local/bin/ruby
#
#
#
require 'getoptlong'
opts = GetoptLong.new(
['--style', '-n', GetoptLong::NO_ARGUMENT ],
['--database', '-i', GetoptLong::REQUIRED_ARGUMENT]
)
$linecount = 0
opts.each do |opt, arg|
case opt
when '--style'
require arg
when '--database'
end
end
#
#
#
# process options
#
#
#
File.open('reference.txt').each do |line|
if line =~ /^tag:/i
$linecount += 1
end
end
puts $linecount
#