laziness, impatience, and hubris | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
What's going wrong in your code is that $1 contains the string "0xdf7780", which Perl does not automatically convert to a number. You can use the hex function to convert it to a number first, and then use sprintf to convert the output back to hex:
However, it's also possible to do it all in one statement, using the special s///e, which runs the replacement part as Perl code and inserts its return value as the replacement, so you can use it to run sprintf directly. I've also used \K and a (?=...) lookahead to exclude those strings from the match, so they're not changed by the replacement.
By the way, you should always Use strict and warnings, and use proper indentation to make your code easier to read (perltidy can help with that). Update: I added the /x modifier to the regex to make it easier to read. Also switched from (?=\ qospri) to (?=\s+qospri) to make it equivalent to the original regex. In reply to Re: Performing addition on hex value extracted from a string
by haukex
|
|