Yes, you need to pack each value individually. Don't worry, as long as you don't run $socket->send() in the inner loop, you're allowed to have another loop. Though, if you want, the documentation could give you some ideas on how to do more than one float in the same call to pack().
Some more hints:
pack outputs a series of octets (bytes) that you can treat like a string: for fun, at the command line, perl -le "print pack 'f', 3.14", and you'll see the funny octets interpreted as strings. You might try other simple one-liners like that, to see what happens when you do different pack templates. The worst that will happen is that your terminal or cmd window will start using funny characters when you type -- at which point, just close it and open a new one. Printing it out is a good way to see what pack is doing.
Since the group of octets is equivalent to a string, you can use any operator or function that manipulates strings, including ones that might concatenate strings (search the docs I linked for 'concatenate', 'concatenation', or synonyms, and I'm sure you'll find an appropriate operator or function), and the results of such activity can be placed in a scalar variable ($DATA_to_be_SENT)
As Mr. Muskrat pointed out, you still haven't said how the encoded floating-points are supposed to be juxtaposed for your hardware; if they are just one right after the other, with no intervening octets, then you can just concatenate the pack() results one after the other; otherwise, you'll have to insert other bytes between, as defined by your hardware requirements. (An inner loop or pack's template should both allow you to easily place zero or more separators between each encoded floating point.)
Once you've got everything concatenated in the way your hardware wants, then you send the string-like scalar to your hardware via the $socket->send($DATA_to_be_SENT);.
I hope this will move you in the right direction. Good luck. | [reply] [d/l] [select] |