In Perl, how do I convert multiple decimal numbers in a line of a file to their hexadecimal equivalents?
I have code which will convert the last number found but leaves the prior numbers unconverted, I want to convert all the numbers not just the last one found:
if ($line =~ /[0-9]+/) {
$loc = index($line,/\s+[0-9]+\s*/);
$mybyte = substr($line,$loc);
$newbyte = sprintf("%x\n", $mybyte);
$newline = substr($line,0,$loc).$newbyte;
print my_report $newline;
}
1 Answer