No, it's plain stupid. oct("0b".$1) is what you want. eval with a string argument starts the huge perl parser, whereas oct uses much more efficient code that can only convert strings to numbers.
Using a string eval is not needed most of the times, and very often, it opens a security hole. JavaFans code does not open a security hole, because it allows only digits to be passed to eval. But it is still wrong, it should allow only 0 and 1, not all digits. And it does not remove the whitespace.
$string=~s/\s*([01]+)/chr oct "0b$1"/eg;
Alexander
--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
| [reply] [d/l] [select] |
Thanks, That means it's sad to say perl5 has no a explicit way to convert number to string each other.
sigh!
I am trying to improve my English skills, if you see a mistake please feel free to reply or /msg me a correction
| [reply] |
But it is still wrong, it should allow only 0 and 1, not all digits.
Not if the question is the more general Is there a way to convert a string to number explicitly like perl6?. Which was what I was answering.
| [reply] |