I’m using \D to not display digits but why the digits are being displayed using perl regular expressions?
Here’s the content of the text2.tx file
1. Hello Brue this is a test. 2. Hello Lisa this is a test. This is a test 1. This is a test 2.
Here is the perl program.
#!/usr/bin/perl
use strict;
use warnings;
open READFILE,"<", "test2.txt" or die "Unable to open file";
while(<READFILE>)
{
if(/\D/)
{
print;
}
}
Lets take a look at what is going on behind the scenes. Your while loop is equivalent to:
So, you are checking if the line contains a non-digit character (which it does) and then printing that line.
If you want to print
Hello Brue this is a test.instead of1. Hello Brue this is a test., then you would have to use something like:Also, it would make for more readable code if you used a variable rather than
$_.