regex - Find n occurrences from group of characters -
Looking at the string, I think of printing "two" if I group xyz <
.
given
jxyl print two
given
jxyzl print nothing
I am very new to Pearl, so this is my view.
my $ word = "jxyl"; @char = split //, $ word; My $ size = $ # four; $ Char eq for "z" ($ i = 0; $ i <$ size - 1; $ i ++) {if ($ char [i] ek "x" || $ char [i] eq " Y ") {print" two "; }} Can anyone tell me why he is not working properly?
From the general question:
perldoc -q count
Use warnings; Strict use; While (& lt; data & gt;) {chomp; My $ count = () = $ _ = ~ / [xyz] / g; Print "$ _ two \ n" if $ count == 2; } __DATA__ jxyl jxyzl jxxl Output:
jxyl two jxxl two
Comments
Post a Comment