Leser: 29
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
#!/usr/bin/perl -w
use strict;
print "Geben sie die Input-Datei ein : ";
my $kyd = <STDIN>;
chomp $kyd;
open(STD, "student.txt") or die;
my %student;
while(){
chomp;
if(/^(\d+)\t(.+)$/){
my $mat_nr = $1;
my $std_name = $2;
$student{$mat_nr} = $std_name;
}
}
open(DB, "datenbank.txt") or die;
my $hit;
my %seen;
my $auswahl;
$auswahl = "Class Auswahl: \n";
while(){
chomp;
if(/$kyd\t(\d*)/i){
$hit = $1;
next if defined $seen{$hit};
$seen{$hit} = 1;
$auswahl .= "$hit $student{$hit}";
}
}
print "$auswahl\n";
Dein Code hier.
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 warnings; my $student_file='student.txt'; my $database_file='datenbank.txt'; print "Geben sie die Input-Datei ein : "; my $kyd = <STDIN>; chomp $kyd; my %student; open(my $fh, '<', $student_file) or die("Can't open $student_file $!\n"); while(<$fh>) { chomp; # <MatrikelNr>\t<Name> $student{$1} = $2 if(/^(\d+)\t(.+)$/); } close($fh); open(my $db, '<', $database_file) or die("Can't open $database_file $!\n"); print "Class Auswahl: \n"; my %seen; while(<$db>) { chomp; if(/$kyd\t(\d*)/i && !$seen{$1}) { $seen{$1} = 1; print "$1 $student{$1}\n"; } } close($db);