Re: Very slim Desktop Manager
On Sun, Nov 16, 2008 at 07:20:07AM +0100, s. keeling wrote:
> #!/usr/bin/perl -w
> #
> # Usage: calcme <string_to_calculate> [<output_format>]
> #
> # Input is a string like (10+3)/7 or "(10 + 3) / 7"
> # Output is the calculated result of the string
> # Optional formatting can be supplied as 2nd parameter.
> #
> my ( $format, $calcme, $output );
>
> if ( @ARGV == 0 || @ARGV > 2 ) {
> die( "Usage: $0 <\"formula_to_calculate\"> [<output_format>]\n: $!" );
> }
>
> $format = "";
> $calcme = $ARGV[0];
> ( @ARGV == 2 ) && ( $format = $ARGV[1] );
>
> $output = eval( $calcme );
>
> if( @ARGV == 1 ) {
> print(STDOUT "$output\n");
> } else {
> printf(STDOUT "$format\n", $output);
> }
>
> exit(0);
>
> __END__
Here's something simpler:
calc() { perl -e "print ''.($*).\"\\n\""; }
$ calc
$ calc 4
4
$ calc 4 + 8
12
$ calc 1/2
0.5
$ calc 'log(22)'
3.09104245335832
(Does not support the extra formatting you have, though)
--
Tzafrir Cohen | tzafrir@jabber.org | VIM is
http://tzafrir.org.il | | a Mutt's
tzafrir@cohens.org.il | | best
ICQ# 16849754 | | friend
Reply to: