IDS_SOMETHIGN_SOMETHING "giving you cookies in a sec"
IDX_SOMETHING_SOMETHIGN "hi again"
IDY_SMOTHIENG_SOMETHIGN_SOMTHIGN "HELO world"
ID_ONE_THING "hello how are you"
ID_ONETHINGTOO "give me a number"
ID_ONEMORE_THING_ANDMORE "this are strings"
I'm trying to create a hash table but i'm not sure what's wrong with my
delimeters:
class Parser
table = { }
IO.foreach('resurcefiletest') { |line|
if line =~ /^ID* (.*?) = \s* " (.*?) "/x #if line =~ /^ \s* " (.*?) " \s* = \s* " (.*?) "/x
table[ $1 ] = $2
end
}
File.foreach filename do |line|
next unless line =~ /^ID(\S+) "(.*?)"/
table[$1] = $2
end
···
On Aug 1, 2006, at 3:35 PM, Robert Smith wrote:
I'm trying to parse a file that looks like this:
text....
numbers....
IDS_SOMETHIGN_SOMETHING "giving you cookies in a sec"
IDX_SOMETHING_SOMETHIGN "hi again"
IDY_SMOTHIENG_SOMETHIGN_SOMTHIGN "HELO world"
ID_ONE_THING "hello how are you"
ID_ONETHINGTOO "give me a number"
ID_ONEMORE_THING_ANDMORE "this are strings"
I'm trying to create a hash table but i'm not sure what's wrong with my
delimeters:
class Parser
table = { }
IO.foreach('resurcefiletest') { |line|
if line =~ /^ID* (.*?) = \s* " (.*?) "/x #if line =~ /^ \s* " (.*?) " \s* = \s* " (.*?) "/x
table[ $1 ] = $2
end
}
#puts table["StaplingTitle"]
p table
end
--
Eric Hodel - drbrain@segment7.net - http://blog.segment7.net
This implementation is HODEL-HASH-9600 compliant
IDS_SOMETHIGN_SOMETHING "giving you cookies in a sec"
IDX_SOMETHING_SOMETHIGN "hi again"
IDY_SMOTHIENG_SOMETHIGN_SOMTHIGN "HELO world"
ID_ONE_THING "hello how are you"
ID_ONETHINGTOO "give me a number"
ID_ONEMORE_THING_ANDMORE "this are strings"
I'm trying to create a hash table but i'm not sure what's wrong with my
delimeters:
class Parser
table = { }
IO.foreach('resurcefiletest') { |line|
if line =~ /^ID* (.*?) = \s* " (.*?) "/x #if line =~ /^ \s* " (.*?) " \s* = \s* " (.*?) "/x
table[ $1 ] = $2
end
}
#puts table["StaplingTitle"]
p table
end
can somebody give me a hand?
---- code: ----
table = {}
DATA.each { |line|
if line =~ /^ID ( \S+ ) \s+ " (.*) "/x
table[ $1 ] = $2
end
}
puts table.to_a.map{|a| a.join " => " }
__END__
text....
text....
numbers....
IDS_SOMETHIGN_SOMETHING "giving you cookies in a sec"
IDX_SOMETHING_SOMETHIGN "hi again"
IDY_SMOTHIENG_SOMETHIGN_SOMTHIGN "HELO world"
ID_ONE_THING "hello how are you"
ID_ONETHINGTOO "give me a number"
ID_ONEMORE_THING_ANDMORE "this are strings"
---- output: ----
_ONE_THING => hello how are you
_ONETHINGTOO => give me a number
Y_SMOTHIENG_SOMETHIGN_SOMTHIGN => HELO world
S_SOMETHIGN_SOMETHING => giving you cookies in a sec
_ONEMORE_THING_ANDMORE => this are strings
X_SOMETHING_SOMETHIGN => hi again