hi,
i seem to be missing something here, can anyone explain why the following:
array_sscanf("foo % 1 2 3 fum", "%s %% %{%d%} %s");
yields
({ "foo", ({ ({ 1 }), ({ 2 }), ({ 3 }) }), "fum" })
and not
({ "foo", ({ 1, 2, 3 }), "fum" })
?
greetings, martin.
Since %{ can contain more than one conversion, it generates an array with the values for each instance it matches:
array_sscanf("foo % 1 0.1 2 0.2 3 0.3 fum", "%s %% %{%d%f%} %s");
(3) Result: ({ /* 3 elements */ "foo", ({ /* 3 elements */ ({ /* 2 elements */ 1, 0.100000 }), ({ /* 2 elements */ 2, 0.200000 }), ({ /* 2 elements */ 3, 0.300000 }) }), "fum" })
If you only have one conversion inside %{, the arrays will of course have only one element. It would be possible to automatically flatten it, but that would make the interface unorthogonal which would be bad. Just flatten the array yourself if you need to.
For your particular example, it would be nice to have %@d, but that is not implemented for sscanf, just for sprintf.
pike-devel@lists.lysator.liu.se