What is the meaning of \ 0 in perl?

$a = "aaata";
$b = "aataa";
$count = ($a ^ $b) =~tr/\0//c;  

pin 2 (due to two miss matches being performed using a flag c) without using pin cflag 3(matches)

Used here \0in tr. Without use tr, the script gives some mascot. I do not know what it is and how to use it trhere and use it \0. In addition, we use \0perl.

+4
source share
2 answers

In general, an escape sequence of three octal digits inserts a character with this code point, therefore, it \40either \040creates a space character and \0creates an ASCII NUL

, $a $b

XOR . , , XOR , NUL. tr/\0//c , NUL (- /c), 2,

$a ^ $b,

"\0\0\25\25\0"

tr/// \25, NUL

+6

^ - xor . ,

$a = "aaata"; $b = "aataa";
printf "%vX\n", ($a ^ $b);

0.0.15.15.0

ord("a" ^ "a") == 0 ord("a" ^ "t") == 0x15 ord("t" ^ "a") == 0x15, ASCII "a" 0x61 0b0110_0001 ( printf "%b\n", ord "a"), ASCII "t" 0x74 0b0111_0100.

, XOR 0b0110_0001 0b0111_0100, 0b0001_0101 0x15.

tr tr/\0//c 5 .

:

tr/SEARCHLIST/REPLACEMENTLIST/cdsr

, . .

/c, SEARCHLIST.

REPLACEMENTLIST , SEARCHLIST. .

perlrebackslash \0. escape-:

. , .

So tr/\0//c tr/\001-\377/\001-\377/ 1 , , .

:

1. \xxx , \077, . perlrebackslash . , tr/\001-\377// \o{} escape tr/\o{1}-\o{377}//

+2

Source: https://habr.com/ru/post/1650397/


All Articles