in reply to Re^2: How to use sprintf %n formatting pattern
in thread How to use sprintf %n formatting pattern

which is about what I'd have expected due to the arguments to printf being evaluated before printf is called

I'm still not sure what you mean by that.

If you call foo($a + $b), perl will calculate $a + $b putting the result in a temporary scalar variable, and put that temporary scalar variable on the stack to call foo(). If you call foo($a), perl will put the scalar variable $a on the stack, and call foo().

In the case of printf("%s%n%.*s\n", $prefix, $stored_width, $limit, $postfix), we get (effectively) references to each of those variables on the stack (at the C level, they are just SV* pointers) - you know they have to be references, since printf needs to be able to write to $stored_width. At the point the printf implementation needs the next argument as a number, it'll ask the relevant scalar what its numeric value is; if it needs a string, it'll ask for that instead, etc.

Is that making it any clearer?

Replies are listed 'Best First'.
Re^4: How to use sprintf %n formatting pattern
by GrandFather (Saint) on Jun 09, 2022 at 21:10 UTC

    Yes, that too came clear in the shower this morning. I think my issue may be related to usually copying arguments into local variables as a first thing so I tend to forget about the aliasing that goes on. You might say I'm 'closing' in on understanding now. :-)

    Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond