Leser: 24
open("...") || die $log->writeError("test");
1 2 3
my $log = LogKlasse->new("logdatei.txt"); # Funktioniert ohne Fehler $log->writeError("test123"); # Funktioniert ohne Fehler open(FILE, ">$outputfile") || die $log->writeError("test456"); #Und hier ist $log undef?!?
1
2
3
4
5
6
7
8
9
10
11
perl -wle'
sub X::foo {
undef $_[0];
print "X::foo()"
}
my $x = bless {}, "X";
$x->foo;
$x->foo;
'
X::foo()
Can't call method "foo" on an undefined value at -e line 7.
1 2 3 4 5 6
package LogKlasse; sub new {...} sub writeError{ print {$fh} $_[1],"\n"; } 1;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
use strict; use warnings; package LogKlasse; my $fh = *STDERR; sub new { bless {}, shift } sub writeErr { print {$fh} $_[1], "\n"; } package main; my $log = new LogKlasse; $log->writeErr("Fehler Nr.1"); open( FILE, "<notarealfile.txt" ) || die $log->writeErr("Fehler Nr.2"); close FILE;