Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Stupid mistakes I repeatedly make

by Corion (Pope)
on Mar 27, 2005 at 17:07 UTC ( #442646=note: print w/ replies, xml ) Need Help??


in reply to Stupid mistakes I repeatedly make

I some times fall for the my ($self, $bar, $baz) = shift; bug, but there is another bug that catches me, especially when I start to consciously think about it instead of letting my fingers interpret my commands:

my $foo = 'bar'; $foo ~= s/a/ee/;

Of course, this is the reversed regex operator (which doesn't exist), and Perl sees this as a syntax error. ambrus taught me a good mnenonic - the negated comparison for the regex binding operator is !~, which has the same order as !=, and thus, the regex binding operator must be =~.

In a certain way this confusion when thinking about what my fingers should be doing reminds me of the problem that octopodes have when coordinating their arms, which, seemingly, they never do - they just send commands to them and then verify the behaviour by optical inspection.


Comment on Re: Stupid mistakes I repeatedly make
Select or Download Code
Re^2: Stupid mistakes I repeatedly make
by jplindstrom (Monsignor) on Mar 27, 2005 at 18:31 UTC
    Heh, I used to do the same thing occasionally as a newbie, and overcame it the exact same way :)

    /J

Re^2: Stupid mistakes I repeatedly make
by demerphq (Chancellor) on Mar 27, 2005 at 18:39 UTC

    ambrus taught me a good mnenonic - the negated comparison for the regex binding operator is !~, which has the same order as !=, and thus, the regex binding operator must be =~.

    I use the same mnemonic but word it a bit differently: I tend to translate $a == $b to "a is b", so I translate $a =~ /Pattern/ as "a is like Pattern", and since ! is traditionally "not" I translate $a !~/Pattern/ as "a not like Pattern".

    Thus the "=~" operator to me is the "is like" operator and the "!~" operator is the "not like" operator.

    ---
    demerphq

Re^2: Stupid mistakes I repeatedly make
by merlyn (Sage) on Mar 27, 2005 at 18:53 UTC

      Teaching is a great way to get paid to say something over and over again so you don't ever forget it. Sadly, there are only four days in our Learning Perl course, and we even say in the first fifteen minutes that we can't teach everything in a week. :)

      --
      brian d foy <brian@stonehenge.com>

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2014-04-17 01:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (437 votes), past polls