Perl - illegal hexadecimal digit warning error

Viewed 229

I'm getting a warning on this line of code:

$mismatch = ($_ =~ s/[^\x0]//g);

Illegal hexadecimal digit ']' ignored at xxxxxx.pl line 61. The regex looks valid to me, what is causing this error please? It's the right square bracket that it doesn't like.

Thanks!

1 Answers

According to the perldoc.perl.org,

Similarly, \xnn, where nn are hexadecimal digits, matches the character whose native ordinal is nn. Again, not using exactly two digits is a recipe for disaster, but you can use \x{...} to specify any number of hex digits.

So, you need to use

s/[^\x00]//g

Or, s/[^\x{0}]//g.

Related