Re: stumped by match()

new topic     » goto parent     » topic index » view thread      » older message » newer message

Ray,

Thanks. Looks like you nailed it. Your e-mail pointed back to the docs, and the
description of gets(). The very first
line reads ...

"Get the next sequence..."     (duuuuhhh!)

Completely explains the results of the program.

Thanks for the help.

Regards,

Jim

Ray & Debbie Smith wrote:

> Hi Jim,
>
> Not being an expert I'll try my best ...
>
> ...from the doco
>
>  Syntax:      i = match(s1, s2)
>
>  Description: Try to match s1 against some slice of s2. If successful,
> return
>               the element number of s2 where the (first) matching slice
> begins,
>               else return 0.
>
> Your sequence of "line"
>
>  line = {"ABCDE.TXT"," 123.456","  345.567","   44444.555","
> END-OF-LINE","Euphoria"}
>
>  is a sequence of sequences, after reading the doco I "think" you can only
> match a single
> sequence s1 against a single sequence s2.
>
> When reading from a file using "gets" it reads one line of a file into a
> single sequence so your "line" above would be a single
> sequence so the match should be able to match the slice.
>
> Hope this helps
>
> Ray Smith
>
> > --------------------------------------------------------------------------
> ---------
> > 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

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu