-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate.pl
More file actions
executable file
·60 lines (45 loc) · 1.18 KB
/
generate.pl
File metadata and controls
executable file
·60 lines (45 loc) · 1.18 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
#!/usr/bin/perl
use strict;
use warnings;
die "Need more arguments. Format: $0 <year> <day>" if (@ARGV != 2);
my $year = $ARGV[0];
my $day = sprintf("%02d", $ARGV[1]);
use File::Basename qw( fileparse );
my $directory = "$year/q$day";
use File::Path qw( make_path );
if ( !-d $directory ){
make_path $directory;
}
# Create input file if doesn't exist
my $inputFilePath = "$directory/q$day\_input.txt";
if (-e $inputFilePath) {
print "Input file in $directory already exists\n";
} else {
open my $inputFh, ">", $inputFilePath;
close $inputFh;
}
# Create problem file if doesn't exist;
createFile("$directory/q${day}a.pl");
createFile("$directory/q${day}b.pl");
sub createFile {
my ( $filePath ) = @_;
my ( $file, $directory ) = fileparse $filePath;
if (-e $filePath) {
print "File $file in $directory already exists\n";
return;
}
my $templateFile = <<"FINAL";
#!/usr/bin/perl
use strict;
use warnings;
open F, "q$day\_input.txt" or die;
chomp(my \@input = <F>);
close F;
foreach my \$line (\@input) {
}
FINAL
open my $scriptFh, ">", $filePath;
print $scriptFh $templateFile;
close $scriptFh;
system("chmod u+x $filePath");
}