{"id":37176,"date":"2019-03-03T18:15:29","date_gmt":"2019-03-03T18:15:29","guid":{"rendered":"https:\/\/www.oracletutoring.ca\/blog\/?p=37176"},"modified":"2019-03-03T18:15:34","modified_gmt":"2019-03-03T18:15:34","slug":"perl-can-a-computer-understand-or-the-way-a-human-does","status":"publish","type":"post","link":"https:\/\/www.oracletutoring.ca\/blog\/perl-can-a-computer-understand-or-the-way-a-human-does\/","title":{"rendered":"Perl: can a computer understand &#8220;or&#8221; the way a human does?"},"content":{"rendered":"\n<h2>Self-tutoring about computer science: the tutor explores the concept of &#8220;or&#8221;.<\/h2>\n\n<p>\nIn English, &#8220;or&#8221; means a choice: ham or bacon, for instance.\n<\/p>\n<p>\nIn computer science, &#8220;or&#8221; is often called a logical operator, implying it yields 1 if true, but 0 if false. Yet, can a computer use &#8220;or&#8221; to make a choice, like a person can? Apparently so. Consider the following Perl code:\n<\/p>\n<p style=\"color:brown;font-family:monospace;font-size:120%; white-space:pre-wrap\">$var1=&#8217;hello&#8217;;\n$var2=$var3||$var1;\nprint $var2;\n<\/p><p>\nThe output:\n<\/p>\n<p style=\"font-family:monospace;font-size:120%\">\nhello<\/p>\n<p>\n$var3 is undefined, while $var1=&#8221;hello&#8221;. || means &#8220;or&#8221;. Given the choice between the undefined $var3 and the defined $var1, Perl chooses the latter and returns &#8220;hello&#8221; rather than 1.\n<\/p>\n<p>Source:\n<\/p>\n<p>\nMcGrath, Mike. <em>Perl in easy steps<\/em>. Southam: Computer Step, 2004.\n<\/p>Jack of <a href=\"https:\/\/www.oracletutoring.ca\">Oracle Tutoring by Jack and Diane,<\/a> Campbell River, BC.\n","protected":false},"excerpt":{"rendered":"<p>Self-tutoring about computer science: the tutor explores the concept of &#8220;or&#8221;. In English, &#8220;or&#8221; means a choice: ham or bacon, for instance. In computer science, &#8220;or&#8221; is often called a logical operator, implying it yields 1 if true, but 0 &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"more-link\" href=\"https:\/\/www.oracletutoring.ca\/blog\/perl-can-a-computer-understand-or-the-way-a-human-does\/\"> <span class=\"screen-reader-text\">Perl: can a computer understand &#8220;or&#8221; the way a human does?<\/span> Read More &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2943],"tags":[],"class_list":["post-37176","post","type-post","status-publish","format-standard","hentry","category-perl"],"_links":{"self":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/37176","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/comments?post=37176"}],"version-history":[{"count":8,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/37176\/revisions"}],"predecessor-version":[{"id":37184,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/37176\/revisions\/37184"}],"wp:attachment":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/media?parent=37176"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/categories?post=37176"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/tags?post=37176"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}