F
fl
Hi,
I am learning an example, see below part. I find that there is a
special message from the running of the example when I input three
\'s (\\\). It says was not found when I input two, four or other
number \.
My question is: 1. Why it only has this output for three \. 2. What is
the meaning: "Trailing \ in regex m/\\\/ at matchtest.plx line 13,
<STDIN> line 1. Thanks.
........
#!/usr/bin/perl
# matchtest.plx
use warnings;
use strict;
$_ = q("I wonder what the Entish is for 'yes' and 'no'," he thought.);
# Tolkien, Lord of the Rings
print "Enter some text to find: ";
my $pattern = <STDIN>;
chomp($pattern);
if (/$pattern/) {
print "The text matches the pattern '$pattern'.\n";
} else {
print "'$pattern' was not found.\n";
}
I am learning an example, see below part. I find that there is a
special message from the running of the example when I input three
\'s (\\\). It says was not found when I input two, four or other
number \.
My question is: 1. Why it only has this output for three \. 2. What is
the meaning: "Trailing \ in regex m/\\\/ at matchtest.plx line 13,
<STDIN> line 1. Thanks.
........
#!/usr/bin/perl
# matchtest.plx
use warnings;
use strict;
$_ = q("I wonder what the Entish is for 'yes' and 'no'," he thought.);
# Tolkien, Lord of the Rings
print "Enter some text to find: ";
my $pattern = <STDIN>;
chomp($pattern);
if (/$pattern/) {
print "The text matches the pattern '$pattern'.\n";
} else {
print "'$pattern' was not found.\n";
}