Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

String match does not work with '+' sign?

Status
Not open for further replies.

whn

Programmer
Joined
Oct 14, 2007
Messages
265
Location
US
Code:
my $a = 'San+Francisco';
my $b = 'San+Francisco';
if($a =~ $b) {
    print "Match: #$a#, #$b#\n";
}
else {
    print "Not Match: #$a#, #$b#\n";
}

Test run:

% ./tt.pl
Not Match: #San+Francisco#, #San+Francisco#

You help is highly appreciated!!
 
Hi

The "+" sign gets interpreted as quantifier meaning character "n" one or more times.
man perlre said:
[tt]\Q quote (disable) pattern metacharacters till \E[/tt]
Code:
[navy]$a[/navy] [teal]=~[/teal] [green][i]"\Q$b\E"[/i][/green]

Feherke.
 
Thanks! Somehow, I cannot add a star. Don't know why. Could the link be broken?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top