?
Solved

pattern matching (again)

Posted on 2000-01-03
6
Medium Priority
?
160 Views
Last Modified: 2013-12-25
Hi there !
It seems as if I have some problems with pattern matching :-) How can I find out if "|" is included in a string $string ? If I try if ($string =~ '|') ... it doesn't work !

regards
ItsMe
0
Comment
Question by:ItsMe
  • 3
  • 2
6 Comments
 

Author Comment

by:ItsMe
ID: 2321063
Edited text of question.
0
 
LVL 4

Accepted Solution

by:
furu earned 80 total points
ID: 2321793
The syntax for the =~ is //. If you want to use ' as a delimiter you _must_ use m''.

$string =~ /|/
or
$string =~ m'|'

I do believe you misunderstand what you do with =~ so I recommend you take a look at the manpages for perlre (Perl Regular Expressions). Using ' as delimiter for =~ makes for a very, very special behavior of interpolating expressions in regexps that I do not believe you want.

Note that
$string =~ m'|'
is very much different from
$string = '|'
and
$string =~ /|/
which is what I believe you want to do.


Y.s.
0
 
LVL 4

Expert Comment

by:furu
ID: 2321796
Now, of course, since it's a bit late and I must be tired, I forgot: | is used for alteration so you should escape it like this:

$string =~ m/\|/;

Y.s.
0
Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

 
LVL 85

Expert Comment

by:ozo
ID: 2321988
actually,
  $string =~ '\|'
would have worked fine too.
0
 
LVL 4

Expert Comment

by:furu
ID: 2321993
Yes, but thing is that '' as regexp delimiters causes no interpolation of variables, so that

$string = "This is a test";
$indata = "test";
print "Match" if $string =~ m'$indata';

would not match...

I'm not sure that's what he was trying to do.
0
 

Author Comment

by:ItsMe
ID: 2322425
thanks thats what I need. (I tried =~ '|' and forgot the \ one time) :-)

regards
ItsMe
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial will discuss the log-in process using WhizBase. In this article I assume you already know HTML. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you might look at some of my other articles abo…
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
The viewer will learn how to dynamically set the form action using jQuery.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

600 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question