{"id":9659,"date":"2015-04-08T19:57:58","date_gmt":"2015-04-08T19:57:58","guid":{"rendered":"http:\/\/www.oracletutoring.ca\/blog\/?p=9659"},"modified":"2015-04-08T19:57:58","modified_gmt":"2015-04-08T19:57:58","slug":"perl-a-command-line-script","status":"publish","type":"post","link":"https:\/\/www.oracletutoring.ca\/blog\/perl-a-command-line-script\/","title":{"rendered":"Perl:  a command-line script"},"content":{"rendered":"<h1>The tutor continues about command-line math.<\/h1>\n<p>Back on <a href=\"?p=9614\">April 6<\/a> I showed how to use <strong>awk<\/strong> to do calculations on the command line.  From my understanding, awk is native to Linux, but not Windows.<\/p>\n<p>If you&#8217;ve got Perl installed on Windows (which I talked about starting <a href=\"?p=4589\">here<\/a>), you can do command-line math using Perl.  Of course, the Linux users can as well:  Perl comes native on Linux.<\/p>\n<p>Let&#8217;s examine the following Perl code, which can be entered on the command line:<br \/>\n<span style=\"font-family:monospace;\"><br \/>\nperl -e &#8220;use Math::Trig;print acos(-1) . chr(10)&#8221;<br \/>\n<\/span><br \/>\n<span style=\"font-family:monospace\"><br \/>\nperl -e &#8220;<em>&#8230;&#8230;.code&#8230;&#8230;.<\/em>&#8221;<br \/>\n<\/span><br \/>\nmeans that the quotes contain Perl code to be executed straight from the command line.<br \/>\n<span style=\"font-family:monospace\"><br \/>\nuse Math::Trig;<br \/>\n<\/span><br \/>\nloads the Perl Trig functions beyond just sin and cos.<br \/>\n<span style=\"font-family:monospace\"><br \/>\nprint acos(-1) . chr(10)<br \/>\n<\/span><br \/>\ndisplays the answer to <strong>arccos(-1)<\/strong>, aka <strong>inverse cos(-1)<\/strong>, which is pi: 3.14159265<\/p>\n<p>The period . in the middle is a concatenation operator; it means, when doing the <span style=\"font-family:monospace\">print<\/span>, that what comes after the period should be printed next.<br \/>\n<span style=\"font-family:monospace\"><br \/>\nchr(10)<br \/>\n<\/span><\/p>\n<p>indicates the printing of a newline.  The Perl <span style=\"font-family:monospace\">chr(<em>number<\/em>)<\/span> operator means &#8220;print the character designated by this number.&#8221;  The number 10 translates to the newline character.<\/p>\n<p>So, to summarize, the command line Perl code<br \/>\n<span style=\"font-family:monospace;\"><br \/>\nperl -e &#8220;use Math::Trig;print acos(-1) . chr(10)&#8221;<br \/>\n<\/span><br \/>\nshould output<\/p>\n<p><span style=\"font-family:monospace\">3.14159265<\/span><\/p>\n<p>then a newline.<\/p>\n<p>HTH:)<\/p>\n<p>Source:<\/p>\n<p><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>The tutor continues about command-line math. Back on April 6 I showed how to use awk to do calculations on the command line. From my understanding, awk is native to Linux, but not Windows. If you&#8217;ve got Perl installed on &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"more-link\" href=\"https:\/\/www.oracletutoring.ca\/blog\/perl-a-command-line-script\/\"> <span class=\"screen-reader-text\">Perl:  a command-line script<\/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,3],"tags":[672,673,674,678,676,675,173,677],"class_list":["post-9659","post","type-post","status-publish","format-standard","hentry","category-computer-science","category-math","tag-perl-command-line-arithmetic","tag-perl-command-line-math","tag-perl-command-line-script","tag-perl-concatenation-operator","tag-perl-inverse-trig-functions","tag-perl-mathtrig","tag-perl-programming","tag-perl-trig-functions"],"_links":{"self":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/9659","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=9659"}],"version-history":[{"count":25,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/9659\/revisions"}],"predecessor-version":[{"id":9684,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/9659\/revisions\/9684"}],"wp:attachment":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/media?parent=9659"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/categories?post=9659"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/tags?post=9659"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}