Every now and then perl reveals a nice sweet feature that I didn't know existed before.
I need to send multiple strings across http. If I were doing this via RFCs I'd probably separate the strings with MIME boundaries. But I need speed and the most compact representation possible, so I'm using network-strings - length followed by the string itself. This way I can support binary strings (the first string contains \0's).
I figured I was going to have to do pack("Na*", length($string), $string)
, but no! Perl's pack() function lets me do:
pack("N/a*", $string)And it all Just Works. The template above gives me a network-string. Sweet.