Thread Split von grosser Datei (17 answers)
Opened by Moep at 2006-05-19 20:30

renee
 2006-05-19 23:10
#66314 #66314
User since
2003-08-04
14371 Artikel
ModeratorIn
[Homepage] [default_avatar]
Code: (dl )
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;
OTRS-Erweiterungen (http://feature-addons.de/)
Frankfurt Perlmongers (http://frankfurt.pm/)
--

Unterlagen OTRS-Workshop 2012: http://otrs.perl-services.de/workshop.html
Perl-Entwicklung: http://perl-services.de/

View full thread Split von grosser Datei