#!/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";
}