calculate math expression with command line by perl

2 views
Skip to first unread message

Copper Hill

unread,
Apr 24, 2009, 12:02:51 AM4/24/09
to worldhunter
1. install Expression.pm
http://search.cpan.org/~jonathan/Math-Calculus-Expression-0.2.2/Expression.pm

2. put the following lines into ~/.bash_profile
cal() {
if [ $# -lt 1 ]; then
echo "Please follow an expression, such as (42.5/1.7)*6."
else
perl -le "use Math::Calculus::Expression;my \$exp =
Math::Calculus::Expression->new;\$exp->setExpression('$1');print \$exp-
>evaluate();"

fi
}

3. cal "(42.5/1.7)*6"
Reply all
Reply to author
Forward
0 new messages