-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathExerciseMove.pl
More file actions
99 lines (85 loc) · 2.32 KB
/
ExerciseMove.pl
File metadata and controls
99 lines (85 loc) · 2.32 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/perl
sub moveDown($$)
{
my $T=$_[0];
my $P=$_[1];
#print ("Moving down $T/$P...\n");
my $N=$P+1;
if (-f "/leats-scripts/${T}/${N}.pl") { &moveDown($T,$N); }
if (-f "/leats-scripts/${T}/${P}.pl")
{
print "Action DOWN ${T}/${P}\n";
my $fh;
my $fh2;
open($fh,"<","/leats-scripts/${T}/${P}.pl");
open($fh2,">","/leats-scripts/${T}/${N}.pl");
my $line;
while ($line=<$fh>)
{
if ($line=~m/our \$problem="$P";/) { print $fh2 "our \$problem=\"$N\";\n"; }
else
{
print $fh2 "$line";
}
}
close($fh);
system("rm -f /leats-scripts/${T}/${P}.pl");
system("mv /leats-scripts/${T}/${P}-solution.pl /leats-scripts/${T}/${N}-solution.pl");
return 0;
}
}
sub moveUp($$)
{
my $T=$_[0];
my $P=$_[1];
my $N=$P-1;
if (-f "/leats-scripts/${T}/${P}.pl")
{
print "Action UP ${T}/${P}\n";
if (-f "/leats-scripts/${T}/${N}.pl") { print "/leats-scripts/${T}/${N}.pl is exist..\n\n"; return 1; }
my $fh;
my $fh2;
open($fh,"<","/leats-scripts/${T}/${P}.pl");
open($fh2,">","/leats-scripts/${T}/${N}.pl");
my $line;
while ($line=<$fh>)
{
if ($line=~m/our \$problem="$P";/) { print $fh2 "our \$problem=\"$N\";\n"; }
else
{
print $fh2 "$line";
}
}
close($fh);
system("rm -f /leats-scripts/${T}/${P}.pl");
system("mv /leats-scripts/${T}/${P}-solution.pl /leats-scripts/${T}/${N}-solution.pl");
my $NN=$P+1;
if (-f "/leats-scripts/${T}/${NN}.pl") { &moveUp($T,$NN); }
return 0;
}
}
sub useage()
{
print "Useage:
ExerciseMoveDown.pl <DIRECTION> <TOPIC>/<PROBLEM>
E.g. ExerciseMoveDown.pl DOWN 05-user-group/3";
exit 0;
}
if ((scalar @ARGV) < 2)
{
&useage;
}
else
{
my $Direction=uc($ARGV[0]);
my @A = $ARGV[1] =~ m/(.*)\/(.*)/g;
my $Topic=$A[0];
my $Problem =$A[1];
print "Topic: $Topic | Problem: $Problem\n";
if (-f "/leats-scripts/${Topic}/${Problem}.pl")
{
if ( $Direction eq "DOWN") { &moveDown($Topic,$Problem); }
elsif ( $Direction eq "UP") { &moveUp($Topic,$Problem); }
}
else{ print "/leats-scripts/${Topic}/${Problem}.pl not exist!\n"; &useage; }
}