{"id":8099,"date":"2015-01-29T20:09:26","date_gmt":"2015-01-29T20:09:26","guid":{"rendered":"http:\/\/www.oracletutoring.ca\/blog\/?p=8099"},"modified":"2015-01-29T20:11:45","modified_gmt":"2015-01-29T20:11:45","slug":"perl-sleep-and-the-bell","status":"publish","type":"post","link":"https:\/\/www.oracletutoring.ca\/blog\/perl-sleep-and-the-bell\/","title":{"rendered":"Perl:  sleep() and the bell"},"content":{"rendered":"<h1>To the tutor&#8217;s mind, Perl code is so easy to write, with so many neat functions, it&#8217;s a great teaching language. \u00a0Today we&#8217;ll have some fun.<\/h1>\n<p>I&#8217;ve heard that some people don&#8217;t like programming in Perl. \u00a0I just can&#8217;t see why not. \u00a0I admit, I&#8217;m not a professional programmer. \u00a0However, for my everyday purposes, Perl is the easiest language. \u00a0Apparently, there are some things outside its scope; \u00a0in such cases I have to use another language. \u00a0When I can use Perl, though, I&#8217;m instantly more confident.<\/p>\n<p>I suspect Perl&#8217;s lack of rules bothers some people. \u00a0After all, Perl&#8217;s slogan is &#8220;There&#8217;s more than one way to do it.&#8221; \u00a0People who love Perl, probably love it for that same reason.<\/p>\n<p>Anyway, when you know exactly what you want to do, and it&#8217;s within Perl&#8217;s scope, you can often just write a few lines and come up with something surprisingly functional. \u00a0Or, surprisingly neat and fun, in this case.<\/p>\n<p>I discovered Perl&#8217;s <span style=\"font-family:monospace\">sleep()<\/span> function yesterday on <a href=\"http:\/\/stackoverflow.com\/questions\/3186474\/how-to-wait-for-a-certain-period-of-time-in-perl-on-linux\">stackoverflow.com<\/a>.  It&#8217;s straightforward:  to pause your program, for example, for 15 seconds, you use the command <span style=\"font-family:monospace\">sleep(15)<\/span>.<\/p>\n<p>What about the bell?  It&#8217;s <span style=\"font-family:monospace\">&#8216;\\a&#8217;<\/span>, meaning &#8220;alert&#8221;, and is (maybe) the sound you hear when your computer boots.  It&#8217;s a throwback to the old typewriter days.  Back then, the typewriter would &#8220;beep&#8221; near the end of the line, alerting that you&#8217;d soon go off the paper if you didn&#8217;t return the carriage.  (I&#8217;m really showing my age.)<\/p>\n<p>So here&#8217;s a little Perl timer which allows you to set the number of seconds before you hear &#8220;beep&#8221;:<\/p>\n<p><span style=\"color:brown;font-family:monospace\"><br \/>\n#\/usr\/bin\/perl<br \/>\n<br \/>\nprint &#8220;Hello:) How long before you want to hear three beeps?\\n&#8221;;<br \/>\nprint &#8220;Enter the number of seconds, please.&#8221;;<br \/>\n$secs=&lt;STDIN&gt;;<br \/>\nsleep($secs);<br \/>\nprint &#8220;\\n\\nHere&#8217;s the bell: \\a\\a\\a \\n&#8221;;<br \/>\n<\/span><\/p>\n<p>I tried this on my Windows and Linux systems.  Sadly, I don&#8217;t hear the bell on my flavour of Linux (although it might work on yours:)).  It does work well on Windows, though; in fact, it can be quite loud.  You may want to adjust your volume downward before running the program:)<\/p>\n<p>I&#8217;ll be looking deeper into the issue of why the bell doesn&#8217;t work (so far) on my flavour of Linux.  My findings I&#8217;ll share in a coming post:)<\/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>To the tutor&#8217;s mind, Perl code is so easy to write, with so many neat functions, it&#8217;s a great teaching language. \u00a0Today we&#8217;ll have some fun. I&#8217;ve heard that some people don&#8217;t like programming in Perl. \u00a0I just can&#8217;t see &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"more-link\" href=\"https:\/\/www.oracletutoring.ca\/blog\/perl-sleep-and-the-bell\/\"> <span class=\"screen-reader-text\">Perl:  sleep() and the bell<\/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":[470,471,173,468,469,472],"class_list":["post-8099","post","type-post","status-publish","format-standard","hentry","category-computer-science","tag-bell","tag-linux","tag-perl-programming","tag-sleep","tag-timer","tag-windows"],"_links":{"self":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/8099","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=8099"}],"version-history":[{"count":29,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/8099\/revisions"}],"predecessor-version":[{"id":8128,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/8099\/revisions\/8128"}],"wp:attachment":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/media?parent=8099"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/categories?post=8099"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/tags?post=8099"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}