I don't see anything particularly wrong with your approach, but I have a few thoughts:
- buf[i] = (int)SvNV(*elem);
buf is define as unsigned char, but you're retrieving reals, and casting them to signed ints?
- If you are going to pass in an array of ints or reals, you should really check they will fit into an unsigned char or cast appropriately to ensure they will.
Maybe that should be buf[i] = (unsigned char)SvNV(*elem); or even buf[i] = (unsigned char)SvUV(*elem);
I'll be passing the char buffer and len to an external C function.
Perl's string scalars can hold any unsigned char value, and carry their length, so why not just pass the pointer and length from a scalar argument?
That way you cannot be passed out of range values so don't have to deal with them.
With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
In the absence of evidence, opinion is indistinguishable from prejudice.