Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re: Re: Why do we say the =~ operator "binds"?

by Wassercrats
on Apr 18, 2004 at 08:16 UTC ( #346066=note: print w/replies, xml ) Need Help??

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

For $var =~ /pattern/, I'd prefer "$var is associated with /pattern/" or for a substitution: "/pattern/ acts upon $var" could be used. Binds makes it sound like a more permanent or default association. Bind would be appropriate when saying "/pattern/ binds with $_."

Replies are listed 'Best First'.
Re: Re: Re: Why do we say the =~ operator "binds"?
by jdporter (Canon) on May 03, 2004 at 04:17 UTC
    "is associated with" isn't any better than "binds" (or "is bound to").
    There is no binding, there is no associating.
    The expressions on the two sides of the =~ are simply arguments to a built-in function.

    It is far more accurate to talk about "applying" the pattern to the string.
    Or, for Jah's sake, why not simply "the string is tested against the pattern"?
    "=~ is the pattern-applying operator."

      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        

        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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://346066]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (2)
As of 2017-04-30 05:17 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (534 votes). Check out past polls.