Here is the latest version of my calculator script. It treats each line of input, stopping on an '=' character, as a separate calculation, and appends the answer after an '=' character. That way you can easily amend the calculation and perform it again.
@rem = '--*-Perl-*--
@echo off
perl "%~dpnx0" %*
goto endofperl
@rem ';
#!perl
#line 8
use strict;
use warnings;
use Win32::Clipboard;
sub X { return sprintf("%x",$_[0]); }
sub x { return X($_[0]); }
my $CLIP = Win32::Clipboard();
my $text = $CLIP->GetText();
my @text = split /\n/, $text;
my @results = ();
for ( @text ) {
s[\x0a][];
s[\x0d][];
s/([^=]+)=.+/$1/; # trim after '='
s/(^|[^0-9\.])0+/$1/g; # remove leading zeros (don't want octal)
print "\$_.=' =\t'.($_)\n";
eval("\$_.=' =\t'.($_)");
print " = $_\n";
push @results, $_;
}
$CLIP->Set(join("\n",@results)."\n");
__END__
4*3
11-4*2
010+020+030 = 61
x(123) = 7b
:endofperl
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|