File: calc.pl

package info (click to toggle)
irssi-scripts 20220704
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 4,204 kB
  • sloc: perl: 75,132; sh: 193; makefile: 6
file content (30 lines) | stat: -rw-r--r-- 685 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use strict;
use vars qw($VERSION %IRSSI);

use Irssi qw(command_bind active_win);
$VERSION = '1.10';
%IRSSI = (
    authors	=> 'Juerd',
    contact	=> 'juerd@juerd.nl',
    name	=> 'Calculator',
    description	=> 'Simple /calc mechanism',
    license	=> 'Public Domain',
    url		=> 'http://juerd.nl/irssi/',
    changed	=> 'Thu Mar 19 11:00 CET 2002',
);

command_bind(
    calc => sub {
	my ($msg) = @_;
	for ($msg) {
	    s/,/./g;
	    s/[^*.+0-9&|)(x\/^-]//g;
	    s/\*\*/^/g;
	    s/([*+\\.\/x-])\1*/$1/g;
	    s/\^/**/g;
	    s/(?<!0)x//g;
	}
	my $answer = eval("($msg) || 0");
	active_win->print($@ ? "$msg = ERROR (${\ (split / at/, $@, 2)[0]})" : "$msg = $answer");
    }
);