File: split-eval.pl

package info (click to toggle)
gpsshogi 0.7.0-3.3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 111,280 kB
  • sloc: cpp: 80,962; perl: 12,610; ruby: 3,929; javascript: 1,631; makefile: 1,202; sh: 473; tcl: 166; ansic: 67
file content (50 lines) | stat: -rwxr-xr-x 1,135 bytes parent folder | download | duplicates (5)
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
#!/usr/bin/perl -w
use Getopt::Std;
use strict;
sub usage() {
  print STDERR "usage: $0 prich-x.txt prich-x-info.txt\n";
  exit 1;
}

my $options = {};
getopts("o:v", $options);
my $output = $options->{o} ? $options->{o} : ".";
my $verbose = $options->{v};
system("mkdir", "-p", $output);

my ($weight, $info) = @ARGV;
usage()
  if (@ARGV+0 != 2);


open INFO, $info || die "open $info $!";
open WEIGHT, $weight || die "open $weight $!";
my $mode = "";
while (my $info=<INFO>) {
  print $info;
  chomp $info;
  if ($info =~ /^\#\*\s+([a-z0-9]+)$/) {
    $mode = $1;
    print STDERR "  make $output/$mode\n"
      if ($verbose);
    system("mkdir", "-p", $output . "/" . $mode);
    next;
  }
  next if ($info =~ /^\#/);

  if ($info =~ /^([A-Za-z0-9]+) ([0-9]+)$/) {
    my ($eval, $dim) = ($1, $2);
    my $out = "$output/$mode/$eval.txt";
    print STDERR "  write in $out, $dim lines\n"
      if ($verbose);
    print STDERR "  WARNING $out exists\n"
      if (-f $out);
    open OUT, "> $out" || die "open $!";
    foreach my $f (1..$dim) {
      my $line = <WEIGHT>;
      print OUT $line;
    }
    close OUT;
  }
}
close INFO;