#!/usr/bin/perl

use strict;

my $cnt = 0;

sub mkfile{
  my $cnt = shift;
  my $a = shift;
  if ( $cnt <10 ) {
    $cnt = '0' . $cnt;
  }
  $a =~ s/\ /_/g;
  $a =~ y/ęóąśłżźćń/eoaslzzcn/;
  $a =~ y/ĘÓĄŚŁŻŹĆŃ/eoaslzzcn/;
  $a =~ s/^(.*?)_(.*?)_.*$/$1_$2/;
  my $file = $cnt . '_' . $a . '.txt';
  return($file);
}

open(A,'aaa');
while(<A>){
  chomp;
  $cnt ++;
  s/[\r\n]*//;
  my $line = $_;
  my ($a,$d) = split(/\s*\/\s*/);
  my $f = mkfile($cnt,$a);
  print "$f\n";
  open(F,">$f");
  print F "$line\n";
  close(F);
}
close(A);
