$line=0;
$datapattn=qr/\G(?!\Z)([+-]?\d*(?:\.\d*)?(?:[Ee][+-]?\d+)?)\*?(\w*)(=?)/o;
#Input the system, before blank line is input
print STDERR "Line Reckon 0.2 beta, press [Enter] for command list
0: ";
CycleIN:while("\n" lt ($_=<>)){
my $leftpart='1';
study;
%{$ls[$line]}=();
while(/$datapattn/go)
{
my $nu=$1;
$nu=1 if $1 eq '+' or (($1 eq '') and ($2 ne ''));
$nu=-1 if $1 eq '-';
$nu=-$nu unless $leftpart;
$leftpart='' if $3; 
$ls[$line]{$2}=(defined $ls[$line]{$2})?($ls[$line]{$2}+$nu):$nu;
$lvl{$2}='1';#list of all variables of the system
};
$line++;
print STDERR "$line: "
};
#Dialog about what to do after blank line
print STDERR
"Solve or
[Continue|eXit|Input lines since \#\#<new>|Remove to end|Help]?";
$_=<>;
if(/H/oi){print "\tLine Reckon v. 0.2 beta
(c) Alexandr Ignatiev, 2007
URL:alexvi.narod.ru\tsupport:ignatus31oct\@mail.ru
Input linear system in format: 
{{['+'|'-'][<number>]['*'][<variable>]['=']}\\n}
<number> can be 1 (default), 1998.5, -1e8, 23.4E-12 etc.
limit of precision is about 1e-14.
<variable> must consist of Latin letters ('q' != 'Q'),
numbers 0-9 or '_'s.
Type empty line for to be asked for a command:
h - this help
i - edit lines since specified number or go to end if none is
(unmodified lines wouldn't disappear)
x - exit LReck
r - make current line empty and last
other letters - continue.
Remarks about IO:
1) Text file or file list with any input can be specified
to the program in command line as 'lreck.pl lsystem.txt';
2) All output (except help and solutions) is printed on
STDERR, what means they will be on screen and only there if
runned with redirected output like 'lreck.pl > result.txt'.";
<>;
print "Output must be of lines like:
+<variable>=<number> - all right, you've solved it.
<linear composition of variables>=<number> - not enough data
to solve completely, but that is true
=<number> - if '=0', there were duplicated data, as
\tx+y=1 
\t2x+2y=2
          - if much more by absolute (as '=-0.8'), 
then it's unsoluable system, and ignore all other lines!
"};
exit if /X/oi;
splice @ls,$line if/R/i;
goto SolveLSysteM if $_ le "\n";
if (/\AI(\d+)/oi) {$line=$1}else{
$line=$#ls+1 if /\AI/oi};
print STDERR $line,': ';
goto CycleIN ;

SolveLSysteM: #Go!
delete $lvl{''};
@lvl=sort keys %lvl;
undef %lvl;
foreach $va(@lvl){
 foreach (@ls){$$_{$va}=0 unless $$_{$va}}};#define all variables
$line=0;
MainReck:foreach $xi(@lvl){
    my $l=$line;
    U:{while($l<=$#ls){last U if abs($ls[$l]{$xi})>1e-14;$l++};
    next MainReck};
    my $a=$ls[$l];
    $ls[$l]=$ls[$line];
    $ls[$line]=$a;
    $a=$$a{$xi};
    foreach(('',@lvl)){$ls[$line]{$_}/=$a};
    foreach $li(@ls){
     unless($li eq $ls[$line]){
       $a=$$li{$xi};
       foreach $va(('',@lvl)){$$li{$va}-=$a*$ls[$line]{$va}}};
    };
    $line++;
};
#Output values.
foreach $l(@ls){
 foreach $n(@lvl){
  if ($$l{$n}){print '+' if $$l{$n}!~/\A[-+]/o;
   if( $$l{$n}!~/\A[+-]?1\Z/o or ($n eq '')){
   print $$l{$n} }else{print '-'if $$l{$n}==-1};
  print $n }
 };
 print '='.-$$l{''}."\n"
};
<>;
