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
#!/usr/bin/perl
use strict;
use warnings;
my $file = '/path/to/src.file';
my $dir = '/path/to/destination_directory/';
my $number_of_entries = 20; # Anzahl Einträge pro Datei;
my $counter = 0;
{
local $/ = "\nDATA";
my @entries = ();
open(my $fh,"<",$file) or die $!;
while(my $entry = <$fh>){
chomp $entry;
$entry = 'DATA' . $entry unless($entry =~ /^DATA/);
push(@entries,$entry);
if(scalar(@entries) == $number_of_entries){
open(my $w_fh,">",$dir.$counter.".txt") or die $!;
print $w_fh $_,"\n" for(@entries);
close $w_fh;
++$counter;
}
}
close $fh;
}
open(my $w_fh,">",$dir.$counter.".txt") or die $!;
print $w_fh $_,"\n" for(@entries);
close $w_fh;