{"id":2313,"date":"2015-11-16T14:29:43","date_gmt":"2015-11-16T22:29:43","guid":{"rendered":"http:\/\/www.wellgolly.com\/?p=2313"},"modified":"2016-03-10T17:25:19","modified_gmt":"2016-03-11T01:25:19","slug":"perl-gotchas-equality","status":"publish","type":"post","link":"https:\/\/www.wellgolly.com\/?p=2313","title":{"rendered":"Perl gotcha\u2019s\u2013equality"},"content":{"rendered":"<p>If you try to compare strings using ==, and you have included the use warnings pragma, you will get a warning, as in the example below. However, Perl will still attempt to convert the string into a number. If the string starts with numbers, Perl will use these, otherwise the string equates to 0.<\/p>\n<p>So my conditional,<br \/>\n<pre><code class=\"preserve-code-formatting\">\nif ($device_id == &#039;5G0E3663&#039;) { ... }<\/code><\/pre><\/p>\n<p>compares two zeros and always returns true. Which in my case made bad things happen.<br \/>\nThe correct way to compare strings is:<br \/>\n<pre><code class=\"preserve-code-formatting\">\nif ($device_id eq &#039;5G0E3663&#039;) { ... }<\/code><\/pre><\/p>\n<p>h\/t <a href=\"http:\/\/www.perlmeme.org\/howtos\/syntax\/comparing_values.html\">perlmeme<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you try to compare strings using ==, and you have included the use warnings pragma, you will get a warning, as in the example below. However, Perl will still attempt to convert the string into a number. If the string starts with numbers, Perl will use these, otherwise the string equates to 0. So &hellip; <a href=\"https:\/\/www.wellgolly.com\/?p=2313\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Perl gotcha\u2019s\u2013equality<\/span><\/a><\/p>\n","protected":false},"author":6,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[32],"tags":[],"class_list":["post-2313","post","type-post","status-publish","format-standard","hentry","category-perl"],"_links":{"self":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/posts\/2313","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2313"}],"version-history":[{"count":0,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=\/wp\/v2\/posts\/2313\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2313"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2313"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wellgolly.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2313"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}