E-Mail:
Get our new Windows 7 eBook (PDF) for $7 with 70+ Tips. Download Now!

Perl Calculator

  • No Related Post

Perl Calculator

Most Linux systems installed with the distro defaults include perl. You probably

recognize perl from it’s widespread use in web applications. It does a great job

in that realm. But perl is also a nearly complete programming language. With
perl installed on your machine, you can take advantage of the full set of perl
math functions, all, of course, from the command line.

Today’s Tweak requires another modification to .bashrc. Simply add these two
lines:

    calc(){ perl -wlne’print eval’; }
    export -f calc

These two lines will allow you access to all perl’s math functions via the
‘eval’ argument.

So, what’s the use of today’s Tweak? Once you’ve written the lines into your
.bashrc file, you can see for yourself. Fire off the perl calculator with the
command calc:

    tony@valhalla ~ $ calc
    6*6*6
    216

See it? This Tweak gives you the ability to calculate mathematical equations,
simple or complex, directly from the command line. You can exit with Ctrl+c.

Now, there’s no more need to open a GUI calculator or reach for one on your
desk. You’ve built everything you need into bash.

What Do You Think?

 
35 queries / 0.348 seconds.