http://qs321.pair.com?node_id=323215

Certain aspects of Perl syntax make sense to my brain. Other constructs, for some reason, simply don't.

I've been using Perl for many years now, and I'm still typing  ~= (when of course I mean  =~) about 25% of the time. The editor flags it as bad syntax right away, but why won't this symbol sink into my brain? Odd.

Whereas my fingers and eyes can instantly type or grok a hideous HoHoLoHo...L or a chain of -> -> -> method calls.

Funny, something about the regexp operator doesn't sink in for me.

Just an observation.

rkg

Replies are listed 'Best First'.
•Re: regexp operator -- same mistake over and over again
by merlyn (Sage) on Jan 22, 2004 at 16:15 UTC
    I've stood in front of hundreds of classrooms all over the world, and said "equal tilde ... equal tilde ... equal tilde" over and over again as we go through the regular expression section of the Llama Class.

    And darn it if you wouldn't catch me making the mistake of typing "tilde equal" occasionally as well.

    So, you're in good company!

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.

Re: regexp operator -- same mistake over and over again
by duff (Parson) on Jan 22, 2004 at 16:37 UTC

    Just wait for Perl6! No asymmetrical binding operator anymore, it's ~~.

    :-)

      Considering perl6 operators are renamed every few weeks, and the long way it has to go yet, there's one thing you can be absolutely sure of, the binding operator in perl6 won't be ~~.

      ;-)

      Abigail

        Yeah and Evil O'Reilly keeps insisting on the changes to sell more copies of Perl6 Essentials.

        *;^)

Re: regexp operator -- same mistake over and over again
by bunnyman (Hermit) on Jan 22, 2004 at 22:14 UTC

    Makes sense to me. Every other operator with the 'equals' in it has the 'equals' last, e.g. += or *= (Otherwise $foo =+ 20 would be parsed as $foo = +20)

    The =~ is the opposite and that makes it confusing.

      by analogy with +=
      $foo ~= s/a/b/;
      should be equivalent to
      $foo = $foo ~ s/a/b/;
      so maybe ~ should be a binary operator that returns the result of the substitution whereas ~= would apply the substitution to $foo
Re: regexp operator -- same mistake over and over again
by Old_Gray_Bear (Bishop) on Jan 22, 2004 at 19:36 UTC
    My other favorite typo is '>-'; as in $ref >- method(). I need to learn how to do edit macros in vi().

    ----
    I Go Back to Sleep, Now.

    OGB

      A "macro edit" in vi? Easy money (unless I misunderstand what you mean, which is entirely possible):

          :%s/>-/->/g
Re: regexp operator -- same mistake over and over again
by davis (Vicar) on Jan 22, 2004 at 23:15 UTC

    I've always read "=~" as "equals, but maybe not quite".... or "approximately" - rendered as "≈" "the wiggly equals sign", which looks similar (enough) to "=~".

    "Equals, but maybe not quite"

    Update: Added HTML entity. Thanks Coruscate!


    davis
    It's not easy to juggle a pregnant wife and a troubled child, but somehow I managed to fit in eight hours of TV a day.

      ≅ -> ≅ || ≅ || ≅
      ≈ -> ≈ || ≈ || ≈

Re: regexp operator -- same mistake over and over again
by bort13 (Novice) on Jan 23, 2004 at 02:27 UTC
    I've always read it as "matches" because it looks like a match, and it goes left to right like everything else does.
Re: regexp operator -- same mistake over and over again
by Juerd (Abbot) on Jan 23, 2004 at 20:43 UTC
Re: regexp operator -- same mistake over and over again
by Anonymous Monk on Jan 25, 2004 at 07:20 UTC
    Best way to remember the order is to remember the order for NOT matching, ie !~ You never have a NOT exclamation point which is not at the start of the operator. Of that you can be sure. So, the matching operator must be =~ rather than ~=
      Yes, this worked for me too. The order seemed completely unnatural when I was first learning Perl but I sort of told myself that ~ is the regex binding operator and the = or ! is a modifier that indicates whether the binding is to be construed as an affirmative or negative one. Pretty kludgy but became second nature soon enough.

              $perlmonks{seattlejohn} = 'John Clyman';

Re: regexp operator -- same mistake over and over again
by artist (Parson) on Jan 23, 2004 at 04:47 UTC
    Your brain thinks that here comes the match/substituion so the special ~ operator has to be used and you type it first.

    In order to overcome these type of issue, you simply have to make a home grown method. Example: it's an 'ee' operator ie.. 'equal tilde' or 'first everyone is equal'. Simple slogans like these and their repeatation will help you going smoothly.

Re: regexp operator -- same mistake over and over again
by demerphq (Chancellor) on Jan 26, 2004 at 23:59 UTC

    FWIW: I always read it as "is like".


    ---
    demerphq

      First they ignore you, then they laugh at you, then they fight you, then you win.
      -- Gandhi


Re: regexp operator -- same mistake over and over again
by bl0rf (Pilgrim) on Jan 24, 2004 at 02:02 UTC
    I'm quite surprised that other monks didn't mention this, which comes quite naturally to me. We read and write from left to right, mathematically we think of 123456... an increase from left to right. It is simply more natural to us to see things increase from left to right and ~= is an increase from the thinner tilde to the thicker equal sign. A decrease seems unnatural.

    Also, on the keyboard the tilde is on the left.