Perl: a command-line script
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’ve got Perl installed on Windows (which I talked about starting here), you can do command-line math using Perl. Of course, the Linux users can as well: Perl comes native on Linux.
Let’s examine the following Perl code, which can be entered on the command line:
perl -e “use Math::Trig;print acos(-1) . chr(10)”
perl -e “…….code…….”
means that the quotes contain Perl code to be executed straight from the command line.
use Math::Trig;
loads the Perl Trig functions beyond just sin and cos.
print acos(-1) . chr(10)
displays the answer to arccos(-1), aka inverse cos(-1), which is pi: 3.14159265
The period . in the middle is a concatenation operator; it means, when doing the print, that what comes after the period should be printed next.
chr(10)
indicates the printing of a newline. The Perl chr(number) operator means “print the character designated by this number.” The number 10 translates to the newline character.
So, to summarize, the command line Perl code
perl -e “use Math::Trig;print acos(-1) . chr(10)”
should output
3.14159265
then a newline.
HTH:)
Source:
Jack of Oracle Tutoring by Jack and Diane, Campbell River, BC.