Thread Filehandler über Array?! (8 answers)
Opened by rucksl at 2006-07-25 20:52

topeg
 2006-07-26 01:15
#68397 #68397
User since
2006-07-10
2611 Artikel
BenutzerIn

user image
Allso hier mal beide Varianten nebeneinander gestellt.

Code: (dl )
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
#!/usr/bin/perl
use strict;
use IO::File;

my @files=();
push(@files,{name=>'/tmp/txt1.txt', nopen=>"r", open=>"<", fh=>undef, nfh=>''});
push(@files,{name=>'/tmp/txt2.txt', nopen=>"r", open=>"<", fh=>undef, nfh=>''});
push(@files,{name=>'/tmp/txt3.txt', nopen=>"r", open=>"<", fh=>undef, nfh=>''});
push(@files,{name=>'/tmp/txt4.txt', nopen=>"r", open=>"<", fh=>undef, nfh=>''});
push(@files,{name=>'/tmp/txt5.txt', nopen=>"r", open=>"<", fh=>undef, nfh=>''});

for my $i (@files)
{
# ALT
open($i->{fh},$i->{open},$i->{name}) or die "Fehler $!\n";

# NEU ( Objektorienetiert )
$i->{nfh}=IO::File->new($i->{name},$i->{nopen}) or die "Fehler $!\n";
}

for my $i (@files)
{
# ALT
# my $txt=readline($i->{fh}); #<= Alternativ
my $fh=$i->{fh};
my $txt=<$fh>;
print "ALT: $i->{name}: $txt\n";

# NEU
my $ntxt=$i->{nfh}->getline();
print "NEU: $i->{name}: $ntxt\n";
}

for my $i (@files)
{
# ALT
close($i->{fh}) or die "Fehler $!\n";

# NEU
$i->{nfh}->close() or die "Fehler $!\n";
}

View full thread Filehandler über Array?!