{"id":8177,"date":"2015-02-02T20:48:16","date_gmt":"2015-02-02T20:48:16","guid":{"rendered":"http:\/\/www.oracletutoring.ca\/blog\/?p=8177"},"modified":"2015-02-02T20:48:16","modified_gmt":"2015-02-02T20:48:16","slug":"perl-sleep-and-the-bell-part-ii","status":"publish","type":"post","link":"https:\/\/www.oracletutoring.ca\/blog\/perl-sleep-and-the-bell-part-ii\/","title":{"rendered":"Perl:  sleep() and the bell, part II"},"content":{"rendered":"<h1>The tutor follows up on an issue that evolved with the ASCII bell character, &#8216;\\a&#8217;, a few posts ago.<\/h1>\n<p>Back on <a href=\"?p=8099\">January 29<\/a> I introduced a Perl program that takes, as input, a waiting time in seconds, then makes three beeps afterwards.  The program uses the ASCII bell character, <span style=\"font-family:monospace\">&#8216;\\a&#8217;<\/span>, to make each beep.<\/p>\n<p>The program worked great on Windows; alas, on my Linux (Ubuntu) system, the bell wouldn&#8217;t ring.  Research revealed that, possibly at several levels in Ubuntu, the ASCII bell has been disabled.  One explanation I read was that programmers got tired of hearing it.  Whatever the reason, I worried my Ubuntu readers might feel left out in the cold.<\/p>\n<p>However, Linux, like Perl, has &#8220;more than one way to do it&#8221;:)  I recalled from <a href=\" http:\/\/www.sthomas.net\/roberts-perl-tutorial.htm\">Robert&#8217;s Perl tutorial<\/a> that Perl has commands to start external processes; I&#8217;d not yet tried any.  At the <a href=\" http:\/\/askubuntu.com\/questions\/41289\/how-do-i-make-the-beep-command-work\">askubuntu<\/a> site, a user called <a href=\"http:\/\/askubuntu.com\/users\/15811\/rinzwind\">Rinzwind<\/a> pointed out that, on the command line,<\/p>\n<p><span style=\"font-family:monospace\">aplay \/usr\/share\/sounds\/alsa\/Front_Center.wav<\/span><\/p>\n<p>could be used to play the <span style=\"font-family:monospace\">Front_Center.wav<\/span> file.<\/p>\n<p>Putting together Robert&#8217;s and Rinzwind&#8217;s advice, I rewrote the Perl program from <a href=\"?p=8099\">Jan 29<\/a> to make it open the external process of playing <span style=\"font-family:monospace\">Front_Center.wav<\/span>, as follows:<br \/>\n<span style=\"font-family:monospace;color:brown\"><br \/>\n#!\/usr\/bin\/perl<br \/>\n<br \/>\n$sound=&#8221;\/usr\/share\/sounds\/alsa\/Front_Center.wav&#8221;;<br \/>\n<span style=\"color:green\">#Above: the sound&#8217;s full name as a string<\/span><\/br><br \/>\nprint &#8220;Hello.  Please enter, in seconds, how long to wait\\n&#8221;;<br \/>\nprint &#8220;before hearing a test sound.&#8221;;<br \/>\n$secs=&lt;STDIN&gt;;<br \/>\nsleep($secs);<br \/>\nprint &#8220;Okay&#8230;here&#8217;s the test sound&#8230;\\n\\n&#8221;;<br \/>\nexec(&#8220;aplay $sound&#8221;); <span style=\"color:green\">#exec opens the external process<\/span><br \/>\n<\/span><\/p>\n<p>This solution worked immediately!:)  I hope it works for you as well.<\/p>\n<p>I am impressed by the Ubuntu community&#8217;s commentary on this matter.  It fortifies my loyalty to Ubuntu as a great operating system.<\/p>\n<p>I&#8217;ll be talking more about Ubuntu and Perl in future posts.  I may even look into recording an actual bell sound for this program, although the benign <span style=\"font-family:monospace\">Front_Center.wav<\/span> test sound works fine for now:)<\/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>The tutor follows up on an issue that evolved with the ASCII bell character, &#8216;\\a&#8217;, a few posts ago. Back on January 29 I introduced a Perl program that takes, as input, a waiting time in seconds, then makes three &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"more-link\" href=\"https:\/\/www.oracletutoring.ca\/blog\/perl-sleep-and-the-bell-part-ii\/\"> <span class=\"screen-reader-text\">Perl:  sleep() and the bell, part II<\/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":[484,481,480,478,471,479,483,173,477,482],"class_list":["post-8177","post","type-post","status-publish","format-standard","hentry","category-computer-science","tag-ascii-a","tag-ascii-a-ubuntu","tag-ascii-bell-ubuntu","tag-external-processes","tag-linux","tag-perl-exec","tag-perl-external-processes","tag-perl-programming","tag-perl-sleep-function","tag-ubuntu"],"_links":{"self":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/8177","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=8177"}],"version-history":[{"count":26,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/8177\/revisions"}],"predecessor-version":[{"id":8203,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/8177\/revisions\/8203"}],"wp:attachment":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/media?parent=8177"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/categories?post=8177"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/tags?post=8177"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}