How does the Perl grep function work with regex?

How the next grep function works (what does !/0o1Iil]/?)

@chars = grep !/0o1Iil]/, 0..9, "A".."Z", "a".."z"; 
use Data::Dumper; 
print Dumper @chars;

to create the following in @chars?

$VAR1 = 0;
$VAR2 = 1;
$VAR3 = 2;
$VAR4 = 3;
$VAR5 = 4;
$VAR6 = 5;
$VAR7 = 6;
$VAR8 = 7;
$VAR9 = 8;
$VAR10 = 9;
$VAR11 = 'A';
$VAR12 = 'B';
$VAR13 = 'C';
$VAR14 = 'D';
$VAR15 = 'E';
$VAR16 = 'F';
$VAR17 = 'G';
$VAR18 = 'H';
$VAR19 = 'I';
$VAR20 = 'J';
$VAR21 = 'K';
$VAR22 = 'L';
$VAR23 = 'M';
$VAR24 = 'N';
$VAR25 = 'O';
$VAR26 = 'P';
$VAR27 = 'Q';
$VAR28 = 'R';
$VAR29 = 'S';
$VAR30 = 'T';
$VAR31 = 'U';
$VAR32 = 'V';
$VAR33 = 'W';
$VAR34 = 'X';
$VAR35 = 'Y';
$VAR36 = 'Z';
$VAR37 = 'a';
$VAR38 = 'b';
$VAR39 = 'c';
$VAR40 = 'd';
$VAR41 = 'e';
$VAR42 = 'f';
$VAR43 = 'g';
$VAR44 = 'h';
$VAR45 = 'i';
$VAR46 = 'j';
$VAR47 = 'k';
$VAR48 = 'l';
$VAR49 = 'm';
$VAR50 = 'n';
$VAR51 = 'o';
$VAR52 = 'p';
$VAR53 = 'q';
$VAR54 = 'r';
$VAR55 = 's';
$VAR56 = 't';
$VAR57 = 'u';
$VAR58 = 'v';
$VAR59 = 'w';
 $VAR60 = 'x';
 $VAR61 = 'y';
 $VAR62 = 'z';
+3
source share
4 answers

Here is grep perldoc . The example in your example uses syntax grep EXPR,LIST, which means that any Perl expression can replace EXPR.

grep takes the list provided to it and returns only those elements where EXPR is true.

EXPR ! /0o1Iil]/ ( ), , /0o1Iil]/. ( 0o1Iil]), .

, , , /[0o1Iil]/, , , . 0 o, 1 I. ..

Btw, grep BLOCK LIST :

@chars = grep { ! /[0o1Iil]/ } (0..9, 'A'..'Z', 'a'..'z');
+6

// - . !/[0o1Iil]/ , " ". , ([) - , , (0/O, I/l/1).

+2

Perl grep:

grep BLOCK LIST

BLOCK LIST , , true.

BLOCK !/0o1Iil]/, true , 0o1Iil]. LIST , grep LIST.

BLOCK : !/[0o1Iil]/, true , 0 1 ai al, LIST , , .

+1

grep .

- - .

. ! not. , , .

0o1Iil] (not 0o1Iil, [ ] .

grep {not /0o1Iil]/} 0..9, A..Z, a..z ( [):

, 0..9, A..Z, a..z 0o1Iil], , - .

grep {not /[0o1Iil]/} 0..9, A..Z, a..z ( [):

, 0, o, 1, I, I l . , - , .

0

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


All Articles