I’m trying to read a document line by line and am interested in only certain characters that are letters, not a new line character.
I have the following:
@chars = split //;
for $char (@chars) {
if ( ($pos % 16569 == 1719)
|| ($pos % 16569 == 8251)
|| ($pos % 16569 == 10238)) {
print FILE_OUT "$char\n";
}
if ($char == m/[A-Z]/) {
$pos++;
}
}
The regular expression m/[A-Z]/ fails to match as $pos never increases. Is it even possible to match an individual char in Perl, or is this operation only allowed for strings? If so, is there a way around this?
You probably mean
=~instead of==.==is the numeric comparison for equality.=~invokes regular pattern matching on the left-hand side of the operator.Oh, and you should also always
use strictanduse warnings, especially in examples.Welcome to StackOverflow.