{"id":6431,"date":"2014-11-19T19:44:06","date_gmt":"2014-11-19T19:44:06","guid":{"rendered":"http:\/\/www.oracletutoring.ca\/blog\/?p=6431"},"modified":"2014-11-19T19:44:06","modified_gmt":"2014-11-19T19:44:06","slug":"perl-getting-input-from-the-user-with-stdin","status":"publish","type":"post","link":"https:\/\/www.oracletutoring.ca\/blog\/perl-getting-input-from-the-user-with-stdin\/","title":{"rendered":"Perl:  getting input from the user with STDIN"},"content":{"rendered":"<h1>Tutoring, you often straddle a couple of generations. \u00a0The tutor reaches back to an old programming tradition&#8230;.<\/h1>\n<p>When I was a kid in the early 80s, computers were very new to have around. \u00a0To make them more appealing to the home market &#8211; where they were suddenly available and even affordable &#8211; computers were given programs that allowed them to interact with the user. \u00a0You&#8217;d see such situations as this:<\/p>\n<p><em>Computer screen<\/em>: \u00a0<span style=\"font-family:monospace;font-size:18px;\">Hello! \u00a0What&#8217;s your name?<\/span><\/p>\n<p><em>The user would type in:<\/em> <span style=\"font-family:monospace;font-size:18px;\">Gerald<\/span><\/p>\n<p><em>Now the computer would reply:<\/em><\/p>\n<p><span style=\"font-family:monospace;font-size:20px;\">Hello, Gerald!  I&#8217;m so glad to meet you!<\/span><\/p>\n<p>How did our predecessors manage that feat &#8211; and how can we do the same?<\/p>\n<p>In Perl, you can do the following:<\/p>\n<p><span style=\"font-family:monospace;color:brown\">#!\/usr\/bin\/perl<br \/>\nprint &#8220;Hello.  What is your name?\\n\\n&#8221;;<br \/>\n$usrname=&lt;STDIN&gt;;<br \/>\nchop $usrname;<br \/>\nprint &#8220;\\nHello, $usrname!  I&#8217;m so glad to meet you!&#8221;;<br \/>\n<\/span><\/p>\n<p><span style=\"font-family:monospace\">&lt;STDIN&gt;<\/span> means for the computer to gather input from the standard source; ie, the console.<\/p>\n<p><span style=\"font-family:monospace\">Chop<\/span> removes the newline (the ENTER stroke) Gerald pressed to &#8220;enter&#8221; his name.<\/p>\n<p>Part of tutoring is continuing traditions:)<\/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, you often straddle a couple of generations. \u00a0The tutor reaches back to an old programming tradition&#8230;. When I was a kid in the early 80s, computers were very new to have around. \u00a0To make them more appealing to the &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"more-link\" href=\"https:\/\/www.oracletutoring.ca\/blog\/perl-getting-input-from-the-user-with-stdin\/\"> <span class=\"screen-reader-text\">Perl:  getting input from the user with STDIN<\/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":[294,173,293],"class_list":["post-6431","post","type-post","status-publish","format-standard","hentry","category-computer-science","tag-getting-input-from-the-user","tag-perl-programming","tag-stdin"],"_links":{"self":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/6431","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=6431"}],"version-history":[{"count":28,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/6431\/revisions"}],"predecessor-version":[{"id":6459,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/6431\/revisions\/6459"}],"wp:attachment":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/media?parent=6431"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/categories?post=6431"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/tags?post=6431"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}