Thread Routinen erzeugen (18 answers)
Opened by bloonix at 2007-01-30 16:53

bloonix
 2007-02-02 16:05
#73857 #73857
User since
2005-12-17
1615 Artikel
HausmeisterIn
[Homepage]
user image
Da fällt mir gerade ein, dass ich die Syslog-Level sowieso als Konstanten
definiert habe:

Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
use constant DEBUG     =>  0;
use constant INFO => 1;
use constant NOTICE => 2;
use constant NOTE => 2;
use constant WARNING => 3;
use constant ERROR => 4;
use constant ERR => 4;
use constant CRITICAL => 5;
use constant CRIT => 5;
use constant ALERT => 6;
use constant EMERGENCY => 7;
use constant EMERG => 7;


Ich könnte also rechte einfach Keys erzeugen.

Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
use constant LEVELS => {
DEBUG => 0,
INFO => 1,
NOTICE => 2,
NOTE => 2,
WARNING => 3,
ERROR => 4,
ERR => 4,
CRITICAL => 5,
CRIT => 5,
ALERT => 6,
EMERGENCY => 7,
EMERG => 7,
}

BEGIN {
for my $level (keys LEVELS) {
no strict 'refs';
my $sub = lc($level);
*{"$sub"} = sub { my $self = shift; $self->_print($level, @_); };
}
}


Aber dann wären die Werte leider nicht mehr konstant. =(
What is a good module? That's hard to say.
What is good code? That's also hard to say.
One man's Thing of Beauty is another's man's Evil Hack.

View full thread Routinen erzeugen