In article <cf*******************@bignews5.bellsouth.net>, Bert
<gr*********@hotmail.com> wrote:
How do I convert an ascii to hex? I want the hex stored in a variable, not
just printed out.
For example,
my testchars = 'CICS003'
How do I store that value in hexchars?
I know this is basic, but it eludes me...
Thanks from a newbie.
You can use ord to get the numerical value of an ascii character and
sprintf "%x" to generate the hexadecimal representation of that number:
#!/opt/perl/bin/perl
use strict;
use warnings;
my $testchars = 'CICS003';
my $hexchars = '';
foreach my $c (split(//,$testchars)) {
$hexchars .= sprintf "%x", ord($c);
}
print "$hexchars\n";
__OUTPUT__
43494353303033
FYI: this newsgroup is defunct. Try comp.lang.perl.misc in the future.