Leser: 2
|< 1 2 >| | 14 Einträge, 2 Seiten |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/usr/bin/perl
use strict;
use warnings;
my %lookup;
for (<DATA>) {
chomp;
my ($k, $v) = split(/ -- /);
$lookup{$k} = $v;
}
while(<>) {
s/^(\w+)\b/$lookup{$1} || $1/e;
print;
}
_ _DATA_ _
uidf2920 -- Schulz
uid60124 -- Maier
uidg1626 -- Muster
uidg1067 -- Mueller
uidf2920 -- Schulz wird zu s/uidf2920/Schulz/
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
#!/usr/bin/perl
#
# lambda-style!
#
use strict;
use warnings;
use Data::Dumper;
my @substitutes;
for (<DATA>) {
chomp;
my ($k, $v) = split(/ -- /);
push @substitutes, sub {s/^$k/$v/;};
}
while(<>) {
for my $repl (@substitutes) { $_ =~ $repl }
print;
}
_ _DATA_ _
uidf2920 -- Bla BlaBla
uid60124 -- Maier
uidg1626 -- Muster
uidg1067 -- Mueller
for my $repl (@substitutes) { &$repl }
push @substitutes, eval "sub {s/^$k/$v/;}";
1 2 3 4 5 6 7 8 9 10 11 12 13
my $substitute= sub { $_; }; for (<DATA>) { chomp; my ($k, $v) = split(/ -- /); print "adding correction for [$k]\n"; $substitute= sub { my $r= shift; sub { s/^$k/$v/ or $r->() } }->( $substitute ); } while(<>) { chomp; $substitute->(); print $_, $/; }
|< 1 2 >| | 14 Einträge, 2 Seiten |