[DGD] parse_string() vs. sscanf()

Jason Cone jcone at cs.tamu.edu
Thu Feb 19 02:12:52 CET 1998


I remembered something that I wanted to ask. :)

Given the following 2 statements:

Statement using sscanf()
========================
    mpArray = allocate(2);
    sscanf("test 9", "%s %d", mpArray[0], mpArray[1]);

Statement using parse_string()
==============================
    mpArray = parse_string("   \
        whitespace = / /       \
        word = /[a-z]+/        \
        number = /[0-9]+/      \
                               \
        Sentence: word number ? to_number", "test 9");

    mixed *to_number(mixed *mpTree)
    {
        return ({ mpTree[0], (int) mpTree[1] });
    }

Knowing that mpArray was delcared as mixed *, mpArray has the value of
{ "test", 9, }) after both of the statement blocks.  My question is, which
one is faster/more efficient?  I realize that this is a trivial parsing
example, but a more complex one could be used instead.  Are there
considerations that need to be taken into account when deciding to use
sscanf() vs. parse_string()?

jc

||==================================================================||
||                         ||  "Hard work spotlights the character  ||
|| Jason H. Cone           ||   of people:  some turn up their      ||
|| Dept. Computer Science  ||   sleeves, some turn up their noses,  ||
|| Texas A&M University    ||   and some don't turn up at all."     ||
|| jcone at cs.tamu.edu       ||             - Sam Ewing               ||
||==================================================================||





List config page:  http://list.imaginary.com/mailman/listinfo/dgd



More information about the DGD mailing list