Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert char string to hex in perl

Tags:

perl

I read this post: How to convert hex to char string in perl to convert hex to chart string.

How can I do reverse operation? I need convert char string to hex in perl. For example, I have string "hello world!" and I must get:

00680065006C006C006F00200077006F0072006C00640021
like image 877
Kirill Avatar asked May 17 '19 09:05

Kirill


1 Answers

Here's another approach. Do it all in one go with a regex.

my $string = 'hello world!';
$string =~ s/(.)/sprintf '%04x', ord $1/seg;
like image 149
Dave Cross Avatar answered Oct 02 '22 14:10

Dave Cross