Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: What is the best way to compare variables so that different types are non-equal?

by BrowserUk (Patriarch)
on Jul 19, 2009 at 16:05 UTC ( [id://781456]=note: print w/replies, xml ) Need Help??


in reply to What is the best way to compare variables so that different types are non-equal?

qr/STRING/msixpo

This operator quotes (and possibly compiles) its STRING as a regular expression. STRING is interpolated the same way as PATTERN in m/PATTERN/. If "'" is used as the delimiter, no interpolation is done. Returns a Perl value which may be used instead of the corresponding /STRING/msixpo expression. The returned value is a normalized version of the original pattern. It magically differs from a string containing the same characters: ref(qr/x/) returns "Regexp", even though dereferencing the result returns undef.

I think the relevant part of the docs is the bit I've highlighted. qr// compiles normalises the regex--which basically means blessing it. Hence the magical behaviour.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
  • Comment on Re: What is the best way to compare variables so that different types are non-equal?
  • Download Code

Replies are listed 'Best First'.
Re^2: What is the best way to compare variables so that different types are non-equal?
by ikegami (Patriarch) on Jul 19, 2009 at 16:10 UTC
    I don't know why you crossed out "compiles".
    >perl -Mre=debug -e"qr/a/" Compiling REx "a" Final program: 1: EXACT <a> (3) 3: END (0) anchored "a" at 0 (checking anchored isall) minlen 1 Freeing REx: "a"
      I don't know why you crossed out "compiles".

      Because the docs I quoted used the term 'normalises'. Can they be both compiled and normalised? Can they be normalised and not compiled or vice versa?


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

        Can they be both compiled and normalised?

        Yes. I didn't mean to imply what you said was wrong.

        Can they be normalised and not compiled or vice versa?

        No.

        qr// always compiles.

        qr// always returns the regex flags when used as as string.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2024-04-23 07:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found