package Unicode; use myConfig qw($cfg); use strict; use DBI; # Konstruktor, DB-Connect sub new{ my $class = shift; my $self = { DBH => undef, }; bless $self, $class; my $dsn = "DBI:mysql:database=$cfg->{mysql}->{base};host=$cfg->{mysql}->{host};port=$cfg->{mysql}->{port}"; eval{ $self->{DBH} = DBI->connect_cached( $dsn, $cfg->{mysql}->{user}, $cfg->{mysql}->{pass}, {RaiseError => 1, PrintError => 0} ); }; return $self; } # hier wird nur das Objekt zurückgegeben sub TIEHASH{ my $class = shift; my $self = $class->new; if($@){ return } else{ return $self} } # erst hier werden die Daten aus der mySQL-Tabelle geholt sub FETCH{ my $self = shift; my $key = shift; # Codepoint decimal, cpd my $q = q(SELECT cpd, name FROM unicode WHERE cpd=?); my $href = {}; eval{ my $sth = $self->{DBH}->prepare($q); $sth->execute($key); $href = $sth->fetchall_hashref('cpd'); }; if($@){ return "Fehler: $@" } else{ return $href->{$key}->{name} } } 1;######################################################################### package main; tie(my %h, 'Unicode') or die $@; print $h{8364}; # EURO SIGN