in reply to Re^2: Converting quoted strings to numbers in array
in thread Converting quoted strings to numbers in array
If you were dealing with a mixture of binary (as 0b...), hexadecimal (as 0x...), and octal strings, e.g. in a loop, then oct would be useful.
When you know it's a hexadecimal string (e.g. /^0x/ && ...), I'd use the hex function. It makes your intent clear and obvious and, in my opinion, the code is far more readable.
The actual result is the same whichever you use:
$ perl -E 'say oct "0x47"; say hex "0x47"' 71 71
And just a word of warning, /^0x/ may not do what you want:
$ perl -E 'say "0x47_not_hex" =~ /^0x/ ? "is hex" : "is NOT hex"' is hex $ perl -E 'say "0x47_not_hex" =~ /^0x[0-9a-fA-F]+$/ ? "is hex" : "is N +OT hex"' is NOT hex
— Ken
|
|---|