Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^2: Misreading m// documentation (perlop =~ )

by QM (Parson)
on Mar 14, 2014 at 17:56 UTC ( [id://1078373]=note: print w/replies, xml ) Need Help??


in reply to Re: Misreading m// documentation (perlop =~ )
in thread Misreading m// documentation

=~ with a string implies regex m//atch
Documented in doc:/perlop#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.

-QM
--
Quantum Mechanics: The dreams stuff is made of

  • Comment on Re^2: Misreading m// documentation (perlop =~ )

Replies are listed 'Best First'.
Re^3: Misreading m// documentation (perlop =~ )
by LanX (Saint) on Mar 14, 2014 at 19:16 UTC
    > If the right argument is an expression rather than a search pattern,

    True, but this doesn't apply here, it's literal a search pattern (i.e. compile time), the m is just optional:

    Both generate exactly the same opcodes:

    "expressions evaluated at runtime" are things like variables or functions or do-blocks...

    DB<103> $x= '\w{3}' => "\\w{3}" DB<104> 'abc' =~ $x => 1 DB<105> sub regex { '\w{3}' } DB<106> 'abc' =~ regex() => 1

    Cheers Rolf

    ( addicted to the Perl Programming Language)

      OK, I see the light now.

      <pedantic>
      There's m//, and =~. m// can be used without =~ to match against $_, or with =~ to match against something else.

      Without the presence of =~, m// can omit the m if the delimiter is //, else it is required.

      =~ expects to see a match, substitution, or translation on the RHS, and assumes a match without m//, s//, y//, or tr//.
      </pedantic>

      And since m//, and =~ are 2 separate entities (that slightly overlap), the documentation doesn't tie these together explicitly (IMHO).

      -QM
      --
      Quantum Mechanics: The dreams stuff is made of

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1078373]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2024-04-23 16:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found