pattern matching (again)

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
ItsMeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ItsMeAuthor Commented:
Edited text of question.
0
furuCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
furuCommented:
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
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

ozoCommented:
actually,
  $string =~ '\|'
would have worked fine too.
0
furuCommented:
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
ItsMeAuthor Commented:
thanks thats what I need. (I tried =~ '|' and forgot the \ one time) :-)

regards
ItsMe
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Scripting Languages

From novice to tech pro — start learning today.