{"id":5774,"date":"2014-10-02T19:04:44","date_gmt":"2014-10-02T19:04:44","guid":{"rendered":"http:\/\/www.oracletutoring.ca\/blog\/?p=5774"},"modified":"2014-10-02T19:05:21","modified_gmt":"2014-10-02T19:05:21","slug":"perl-variable-status-the-if-test","status":"publish","type":"post","link":"https:\/\/www.oracletutoring.ca\/blog\/perl-variable-status-the-if-test\/","title":{"rendered":"Perl:  $variable status:  the &#8220;if&#8221; test"},"content":{"rendered":"<h1>Tutoring computer programming, some issues that seem negligible become very important to consider. \u00a0The tutor discusses the status of variables.<\/h1>\n<p>&nbsp;<br \/>\nIn computer programming blogs, as well as in some books, you&#8217;ll often see the construction<\/p>\n<p><span style=\"font-family:monospace\">if($variable)<br \/>\n{<br \/>\nthese instructions;<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\nthese instructions;<br \/>\n}<\/span><\/p>\n<p>The idea is that if <span style=\"font-family:monospace\">$variable<\/span> has been defined and given a non-zero value, for example<\/p>\n<p><span style=\"font-family:monospace\">$variable=14;<\/span><\/p>\n<p>or<\/p>\n<p><span style=\"font-family:monospace\">$variable=&#8221;hello&#8221;;<\/span><\/p>\n<p>then the program will execute the &#8220;if&#8221; set of instructions.  However, if<\/p>\n<p><span style=\"font-family:monospace\">$variable=0;<\/p>\n<p>or <span style=\"font-family:monospace\">$variable<\/span> is simply not declared in the program, the &#8220;else&#8221; set of instructions will be executed.<\/p>\n<p>As we&#8217;ll see in coming posts, this &#8220;if&#8221; test is very convenient.  Moreover, you see it so often in articles about programming, you might think it&#8217;s generic.  However, <strong>not all programming languages support the &#8220;if&#8221; test as written above. <\/strong> Rather, some require an expression in the parentheses, such as<\/p>\n<p><span style=\"font-family:monospace\">if($variable equals value)<\/span><\/p>\n<p>or <\/p>\n<p><span style=\"font-family:monospace\">if($variable not equal to value)<\/span><\/p>\n<p>Happily, Perl <strong>does<\/strong> support the <span style=\"font-family:monospace\">if($variable)<\/span> test. I wonder if some writers who use it in articles are Perl programmers who forget that it doesn&#8217;t work in some other languages.<\/p>\n<p>I&#8217;ll be exploring the &#8220;if&#8221;, &#8220;else&#8221; construction, as well as the &#8220;if&#8221; test, in future posts.  Cheers:)<\/p>\n<p><em>Source:<\/em> <a href=\"http:\/\/www.sthomas.net\/roberts-perl-tutorial.htm\">Robert&#8217;s Perl Tutorial<\/a><\/p>\n<p>Jack of <a href=\"https:\/\/www.oracletutoring.ca\">Oracle Tutoring by Jack and Diane,<\/a> Campbell River, BC.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Tutoring computer programming, some issues that seem negligible become very important to consider. \u00a0The tutor discusses the status of variables. &nbsp; In computer programming blogs, as well as in some books, you&#8217;ll often see the construction if($variable) { these instructions; &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"more-link\" href=\"https:\/\/www.oracletutoring.ca\/blog\/perl-variable-status-the-if-test\/\"> <span class=\"screen-reader-text\">Perl:  $variable status:  the &#8220;if&#8221; test<\/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":[105],"tags":[241,173,240,239],"class_list":["post-5774","post","type-post","status-publish","format-standard","hentry","category-computer-science","tag-perl-if-test","tag-perl-programming","tag-variable-defined-or-undefined","tag-variable-status"],"_links":{"self":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/5774","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=5774"}],"version-history":[{"count":17,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/5774\/revisions"}],"predecessor-version":[{"id":5791,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/5774\/revisions\/5791"}],"wp:attachment":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/media?parent=5774"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/categories?post=5774"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/tags?post=5774"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}