Nowayz Nowayz - 1 year ago 160
Perl Question

How to convert a hex-encoded string to a byte string in Perl?

My original code is in Python, but I need to convert it to Perl for some libraries that I don't have at my disposal in Python.

In Python I would do this:



This would create a string containing the binary representation of:

0xF0 0x00 0x00 0x00 0xF6 0x90 0x5C 0x45 etc...

Now that my string is a byte array I can send it as the payload for my packet. How do I do it Perl?

Mat Mat
Answer Source

You can use the pack function for this.


$ perl -e 'print pack("H*", "303132616263"), "\n";'

Check out the pack tutorial.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download