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

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -