{"id":7474,"date":"2015-01-01T23:21:15","date_gmt":"2015-01-01T23:21:15","guid":{"rendered":"http:\/\/www.oracletutoring.ca\/blog\/?p=7474"},"modified":"2015-01-01T23:22:19","modified_gmt":"2015-01-01T23:22:19","slug":"perl-arrays-referencing-with-the-dollar-sign","status":"publish","type":"post","link":"https:\/\/www.oracletutoring.ca\/blog\/perl-arrays-referencing-with-the-dollar-sign\/","title":{"rendered":"Perl arrays:  referencing with the dollar sign"},"content":{"rendered":"<h1>Tutoring computer science, small details can be very meaningful. \u00a0The tutor brings up an important one about Perl array referencing.<\/h1>\n<p>&nbsp;<br \/>\nBack in my <a href=\"?p=5793\">Oct 4<\/a> post, I introduced a Perl program that searches a grocery list for olive oil.  The items in the list are stored in an array; the program checks the items one by one to see if that particular item is olive oil.<\/p>\n<p>A point is that while the array is called <span style=\"font-family:monospace\">@groceries<\/span>, a single element in the array is referenced using <span style=\"font-family:monospace\">$groceries[index]<\/span>. For example, the zeroth element is referenced by <span style=\"font-family:monospace\">$groceries[0]<\/span>.  <em>The dollar sign is used to reference a single element in the array.<\/em><\/p>\n<p>Another point, which is just a reminder, is that Perl arrays start at position 0.  Therefore, the third element in @groceries is $groceries[2].  Perl sees it as $groceries[0], $groceries[1], $groceries[2]&#8230;.<\/p>\n<p>My compiler seems rather relaxed about whether I use $groceries[2] or @groceries[2] to reference the third element in the array.  However, everywhere I read says to reference a single array element with $array[index] rather than @array[index]; I guess we will.<\/p>\n<p>HTH &#038; HNY:)<\/p>\n<p>Sources:<\/p>\n<p><a href=\"http:\/\/www.sthomas.net\/roberts-perl-tutorial.htm\">Robert&#8217;s Perl tutorial<\/a><\/p>\n<p>McGrath, Mike.  <em>Perl in easy steps.<\/em>  Southam:  Computer Step, 2004.<\/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 science, small details can be very meaningful. \u00a0The tutor brings up an important one &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"more-link\" href=\"https:\/\/www.oracletutoring.ca\/blog\/perl-arrays-referencing-with-the-dollar-sign\/\"> <span class=\"screen-reader-text\">Perl arrays:  referencing with the dollar sign<\/span> Read more \u2192<\/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":[397,396,173],"class_list":["post-7474","post","type-post","status-publish","format-standard","hentry","category-computer-science","tag-array-element-referencing","tag-arrays","tag-perl-programming"],"_links":{"self":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/7474","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=7474"}],"version-history":[{"count":19,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/7474\/revisions"}],"predecessor-version":[{"id":7493,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/7474\/revisions\/7493"}],"wp:attachment":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/media?parent=7474"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/categories?post=7474"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/tags?post=7474"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}