Perl regex matches string differently when providing it as variable -


I got a question about regex matching in Perl. See the following code snippet:

  My $ r = '^ \ z'; My $ s = ""; $ R = ~ / $ s /? Print "match \ n": print "no match \ n"; Output: Match   

The following snippet prints:

  My $ r = '^ \ z'; $ R = ~ / "" /? Print "match \ n": print "no match \ n"; Output: No matching   

Why? Is this a Perl syntax thing that I do not understand?

  my $ s = "";   

is identical

  my $ s = '';   

or

  my $ s = q ();   

i.e. It draws empty string to $ s .

  $ r = ~ / "" /   

You are checking that there are two double quotes in $ r.

To specify a pair of double quotes in $ s,

  my $ s = '' ';;    

Comments

Popular posts from this blog

Out of index C/C++ -

regex - PatternSyntaxException: while using String.ReplaceAll function in java? -

java - Projects which are accessed via multiple (different) IDEs: Ant or Maven? -