I know I’m doing something stupid here, but I’m tired and I’m apparently just not seeing it. I have the following script:
#!/usr/bin/perl
use strict;
use warnings;
my @names = (
"John Q. Public",
"James K Polk"
);
foreach (@names)
{
print "Before: $_\n";
s/\b[A-Z]\.?\b//;
print "After: $_\n";
}
When I run this script, I get the following output:
Before: John Q. Public
After: John . Public <== Why is the period still here?
Before: James K Polk
After: James Polk
Note that in the John Q. Public example, the period is left. Isn’t the optional match argument (?) greedy? According to the perlre docs:
? Match 1 or 0 times
Shouldn’t the period disappear along with the middle initial? What am I missing here?
The problem is