in reply to String to hex
This seems pretty legible
sub str_to_hex { my $str = shift; return "0x" . substr(unpack("H*", $str), 0, 4); } print str_to_hex("COM7") . "\n"; # outputs: 0x434f
In Section
Seekers of Perl Wisdom
in reply to String to hex
This seems pretty legible
sub str_to_hex { my $str = shift; return "0x" . substr(unpack("H*", $str), 0, 4); } print str_to_hex("COM7") . "\n"; # outputs: 0x434f