Official Behavior of $str =~ $pattern

I

++imanshu

1 if ('abc' =~ 'ab')
2 {
3 print 'hello, world'
4 }

The snippet above prints 'hello, world' even though the RHS of =~
isn't inside // or m{}.

I have some legacy code which does a lot of this. Could you point me
to the official behaviour of such expressions in RHS, please.

Thank You,
Himanshu
 
P

Peter Makholm

++imanshu said:
The snippet above prints 'hello, world' even though the RHS of =~
isn't inside // or m{}.

I have some legacy code which does a lot of this. Could you point me
to the official behaviour of such expressions in RHS, please.

It is documented in 'perldoc perlop' look for the paragraph named
'Binding Operators':

If the right argument is an expression rather than a search pattern,
substitution, or transliteration, it is interpreted as a search
pattern at run time. Note that this means that its contents will be
interpolated twice, [...]

//Makholm
 
I

++imanshu

++imanshu said:
The snippet above prints 'hello, world' even though the RHS of =~
isn't inside // or m{}.
I have some legacy code which does a lot of this. Could you point me
to the official behaviour of such expressions in RHS, please.

It is documented in 'perldoc perlop' look for the paragraph named
'Binding Operators':

  If the right argument is an expression rather than a search pattern,
  substitution, or transliteration, it is interpreted as a search
  pattern at run time. Note that this means that its contents will be
  interpolated twice, [...]

//Makholm

Sorry, missed that one. Just what I was looking for.

Thank You,
Himanshu
 

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
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top