2 Einträge, 1 Seite |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/perl
package Tie::Handle::Duplicate;
use strict;
use warnings;
use FileHandle;
sub TIEHANDLE {
my $class = shift;
my $fname = shift;
die "Second argument must be a filename!\n"
unless defined $fname or $fname eq '';
my $self = {};
my $fh = new FileHandle;
if ( $fh->open($fname, '>>') ) {
$self->{'fh'} = $fh;
} else {
die "Can't open file in write mode: $!\n"; }
return bless $self, $class;
}
sub PRINT {
my $self = shift;
$self->{'fh'}->print( @_ );
print STDOUT @_;
}
sub PRINTF {
my $self = shift;
$self->{'fh'}->printf( @_ );
printf STDOUT @_;
}
package main;
use strict;
use warnings;
tie *DUPOUT, 'Tie::Handle::Duplicate', $ENV{'HOME'} . '/tmp/logfile';
select DUPOUT;
printf "%s\n", 'hiho';
sub DESTROY { $_[0]->{'fh'}->close; }
2 Einträge, 1 Seite |