Math-Expr-LATEST
view release on metacpan or search on metacpan
Expr/FormulaDB.pm view on Meta::CPAN
#!/usr/bin/perl
# FormulaDB.pm - A db of formulas and there properties
# (c) Copyright 1998 Hakan Ardo <hakan@debian.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
=head1 NAME
Math::Expr::FormulaDB - A db of formulas and there properties
=head1 SYNOPSIS
require Math::Expr::FormulaDB;
$db=new Math::Expr::FormulaDB($file);
=cut
package Math::Expr::FormulaDB;
use strict;
use Math::Expr;
require Math::Expr::Rule;
sub new {
my $self = bless {}, shift;
$self->Load(shift);
my $db;
my ($vl, $hl);
foreach ($self->Keys) {
$db=$self->Get($_);
$vl=Parse($db->{'vl'}); $vl=$vl->Simplify;
$hl=Parse($db->{'hl'}); $hl=$hl->Simplify;
$db->{'for'}= new Math::Expr::Rule($vl, $hl);
$db->{'back'}= new Math::Expr::Rule($hl, $vl);
}
$self;
}
sub Load {
my ($self, $file) = @_;
if (-f $file) {$self->LoadFile($file);}
if (-d $file) {$self->LoadDir($file);}
}
sub LoadFile {
my ($self, $file) = @_;
my %t;
open (F, "<$file");
while (<F>) {
if (/^([^:]+)\s*:\s*(.*)$/) {
my $a=lc($1);
if (defined $t{$a}) {$t{$a}.="\n$2";} else {$t{$a}=$2;}
}
if (/^\s*$/ || eof F) {
if ($t{'name'}) {
my $t=$t{'name'};
delete $t{'name'};
foreach (keys %t) {
$self->{'opps'}{$t}{$_}=$t{$_};
delete $t{$_};
}
}
}
}
( run in 2.552 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )