Problem with substitute

A

Andreas Grupp

Hello

I have the following code (reduced to reproduce the significant part of
the problem) which produces an error:

#!/usr/bin/perl -w
$horizcode = '<a href="test">*Start</a>';
$tiefsterMenuText = '*Start';
$horizcode s=~ !$tiefsterMenuText!<span>$tiefsterMenuText</span>!;

Error is ==> Quantifier follows nothing in regex

Perl sees the substition as:

$horizcode s=~ !*Start!<span>$tiefsterMenuText</span>!;

and interprets the "*" in the search-part of this substitute.

How can I solve this problem and search for a string with a leading "*"?

Andreas
 
P

Paul Lalli

Hello

I have the following code (reduced to reproduce the significant part of
the problem) which produces an error:

#!/usr/bin/perl -w
$horizcode = '<a href="test">*Start</a>';
$tiefsterMenuText = '*Start';
$horizcode s=~ !$tiefsterMenuText!<span>$tiefsterMenuText</span>!;
^^^
That's not right.
Error is ==> Quantifier follows nothing in regex

Perl sees the substition as:

$horizcode s=~ !*Start!<span>$tiefsterMenuText</span>!;

and interprets the "*" in the search-part of this substitute.

How can I solve this problem and search for a string with a leading "*"?


$horizcode =~ s!\Q$tiefsterMenuText\E!<span>$tiefsterMenuText</span>!;

perldoc -f quotemeta
for more information.

Paul Lalli
 
A

Andreas Grupp

Paul said:
^^^
That's not right.

Sorry this was a typo-error by me. The "s" should have been at the
correct place.
$horizcode =~ s!\Q$tiefsterMenuText\E!<span>$tiefsterMenuText</span>!;

Great! This solved the problem!
perldoc -f quotemeta for more information.

I will read this - Thanks a lot!!!!

Andreas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,159
Messages
2,570,879
Members
47,415
Latest member
PeggyCramp

Latest Threads

Top