No i jak mowilem... dokladnie 11 minut zajelo - uprzedzam jednak, sprawdzane jedynie na podanym wyzej przykladzie...
Usage: wezly.pl <in-test.txt> <in-modify.txt> <wezly-skip.txt> [Y]
wezly.pl:
Kod:
#!/usr/bin/perl -Tw
use strict;
use vars qw/%test %modify $Y/;
# usage
if ($#ARGV < 2) {
print "Usage:\n\t wezly.pl <in-tested.txt> <in-changed.txt> <nodes-skip.txt>\n";
exit 0;
}
# load data
if (open (FH, $ARGV[0])) {
while (<FH>) {
chomp;
next if (!/^\d/);
my @tmp = split(/\s+/);
$test{$tmp[0]} = $tmp[$#tmp];
}
close (FH);
} else {
die "Can't open file $ARGV[0]: $!\n";
}
if (open (FH, $ARGV[1])) {
while (<FH>) {
chomp;
next if (!/^\d/);
m/^(\d+)/;
$modify{$1} = $_;
}
close (FH);
} else {
die "Can't open file $ARGV[1]: $!\n";
}
if (open (FH, $ARGV[2])) {
while (<FH>) {
chomp;
next if (!/^\d$/);
delete $test{$_};
}
close (FH);
} else {
die "Can't open file $ARGV[2]: $!\n";
}
# get Y
print "Y = ";
chomp(my $Y=<STDIN>);
# do testing on what has left after loading nodes list
foreach my $node (keys %test) {
$test{$node} > $Y ? $modify{$node} = '** ' . $modify{$node} : undef;
}
# print results to STDOUT (yup! be flexible and redy to be redirected!)
open (FH, '>wezly-out.txt') || die "Can't open output file: $!\n";
foreach my $node (sort keys %modify) {
print FH "$modify{$node}\n";
}
close (FH);
Dane testowe copy'n'paste z tego co podales w opisie. Plik wezly-skip.txt zawiera numery wezlow do pominiecia w testach, jeden numer w kazdej linii (w testach mialem 1, 2, 4 i 6).
Wynik zapisany do wezly-out.txt to:
Kod:
1, 93, 297, 20, 1, 1424, 1628, 1351, 1332
2, 297, 298, 21, 20, 1628, 1629, 1352, 1351
** 3, 298, 299, 22, 21, 1629, 1630, 1353, 1352
4, 299, 300, 23, 22, 1630, 1631, 1354, 1353
** 5, 300, 301, 24, 23, 1631, 1632, 1355, 1354
6, 301, 302, 25, 24, 1632, 1633, 1356, 1355
Czyli ok, bo zgodnie z wartosciami wiersz 2 tez powinien byc zmieniony :-)
Mam nadzieje ze sie przyda :-)