Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^4: Why do we say the =~ operator "binds"? (unapplied?)

by tye (Cardinal)
on May 03, 2004 at 07:07 UTC ( #349944=note: print w/ replies, xml ) Need Help??


in reply to Re: Re: Re: Why do we say the =~ operator "binds"?
in thread Why do we say the =~ operator "binds"?

If "=~ is the pattern applying operator", then code like if( /foo/ ) would never apply the regex. The two sides of =~ are *not* passed to some built-in function as arguments. The right-hand side is what is run and the left-hand side is the argument if it is present. An "unbound" regex still gets applied. Matching happens even without =~.

The =~ (mostly) is *not* what makes pattern matching happen. The regex is what makes pattern matching happen and the =~ (if present) binds a string to the regex to tell it what to match against (other than the default).

Now, if you have =~ with something that isn't a regex to its right, then you have rather bizarre code and are at the mercy of dubious "do what I mean" guessing. If Perl happens to currently insert a regex constructor for you, my main reaction is that I know I have no code that relies on such.

So the reason we say 'bind' is because one side is the code to run. Like '(' is used to bind arguments to a function -- '(' is not "the function invoking operator", despite that description being somewhat appropriate.

- tye        


Comment on Re^4: Why do we say the =~ operator "binds"? (unapplied?)
Download Code
Re: Re^4: Why do we say the =~ operator "binds"? (unapplied?)
by jdporter (Canon) on May 03, 2004 at 13:41 UTC
    There's two issues, happening at two levels of abstraction. At a low (more concrete) level, the two sides of =~ are two arguments of a built-in function. (Yes, at an even lower level, there is no actual such function.) The absence of =~ and its LHS simply indicate to use a default argument there. What to call the =~ operator is an issue at a higher (more abstract) level. It doesn't have to correspond to what's really happening inside the interpreter, or even what we think is happening; but it should accurate reflect how we think of the operator conceptually. And by this standard, "bind" (or "associate") is a very poor choice of terms. Even given your analogy that a regex is kind of function, arguments do not get "bound" to functions. (Arguments get "bound" to parameters, but even that terminology is rarely seen in the Perl community.) I happen to think that "pattern applying" works, but I'll happily concede that there may be something better. "Regex argument passing operator" sounds like it may be accurate, but obviously is unacceptably long.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (8)
As of 2014-10-02 07:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    What is your favourite meta-syntactic variable name?














    Results (49 votes), past polls