stumped by match()
Been studying Euphoria for a few weeks, trying out each statement, until I felt
I fully understood how it worked. But I
have now met my match(). Completely stumped. The following program demonstrates
my bewilderment. Match() seems to work
as expected (re; the docs and sample program gets.ex provided with Euphoria), as
long as the sequence to be matched
against is read in from a file; does not work as expected if s2 is hard-coded in
the prog.
Clearly, I have a problem in understanding how match() is to be used, as the
following program demonstrates.
-----------------------------------------------------------------------------------
include get.e
include file.e
include wildcard.e
allow_break(1)
with trace
sequence seq
integer char,FoundSpaceAt,FoundTextAt, true, false,i,e,finally,fn
atom adam
object string1,string2,string3,string4,string5,string6,string7,line,TextFile,
line2,TestString
true = 1
false = 0
string1 = {" "}
string2 = {"OF-LIN"}
string3 = ","
string4 = "END-OF"
string5 = {32}
string6 = {32,32}
string7 = {34,36}
finally = false
line = {"ABCDE.TXT"," 123.456"," 345.567"," 44444.555","
END-OF-LINE","Euphoria"}
trace(1)
FoundSpaceAt = match(string1,line) -- doesn't work, returns 0
FoundTextAt = match(string2,line) -- doesn't work, returns 0
FoundTextAt = match(string3,line) -- doesn't work, returns 0
FoundSpaceAt = match(string4,line) -- doesn't work, returns 0
FoundTextAt = match(string5,line) -- doesn't work, returns 0
FoundSpaceAt = match(string6,line) -- doesn't work, returns 0
FoundTextAt = match(string7,line) -- doesn't work, returns 0
if match("Euphoria", line) then
FoundTextAt = match("Euphoria", line) -- doesn't work, returns 0
end if
i = match("Euphoria",line) -- nope, returns 0
--------------------------------
-- try reading it from a file
--------------------------------
fn = open("test.prt","rb")
if fn = -1 then
puts(1,"Open failed")
end if
TextFile = fn
line2 = gets(TextFile) -- identical data to
'line', above
if atom(line2) then
close(TextFile)
end if
if match("Euphoria", line2) then -- read from file - works, Why?
finally = true
end if
if match(" ", line2) then
FoundSpaceAt = match(" ", line2) -- read from file - works, Why?
end if
TestString = "Euphoria"
if match(TestString, line2) then
FoundTextAt = match(TestString, line2) -- read from file - works, Why?
end if
abort(1)
------------------------------------------------------------------------------------------------------------
Appreciate any and all offers of help.
Thanks,
Dumbfounded (maybe just dumb??)
Jim
|
Not Categorized, Please Help
|
|