Good Day,
I have a simple working routine in Perl that swaps two words:
i.e. John Doe —–> Doe John
Here it is:
sub SwapTokens()
{
my ($currentToken) = @_;
$currentToken =~ s/([A-Za-z]+) ([A-Za-z]+)/$2 $1/;
# $currentToken =~ s/(\u\L) (\u\L)/$2 $1/;
return $currentToken;
}
The following usage yields exactly what I want:
print &SwapTokens("John Doe");
But when I uncomment out the line ‘$currentToken =~ s/(\u\L) (\u\L)/$2 $1/;
I get an error. Am I missing something, it looks like my syntax is correct.
TIA,
coson
\Lmeans “lowercase till\E“; i.e., it needs to be followed at some point by\E. You do not have\Ein your regex, thus it is not valid; adding\Eafter each\Lgets the script to compile, though I have no idea what you are actually trying to accomplish there.