Thread [S]Möglichkeit um Textdateien aufzuteilen
(5 answers)
Opened by pr0ViL at 2008-04-13 15:22
ungetestet:
Code (perl): (dl
)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 for my $file (@list_of_files) { open my $read, '<', $file or die $!; my $count = 0; my $new_name = "$file$count"; open my $write, '>', $new_name or die $!; while (my $line = <$read>) { print $write $line; if ($. % 25 == 0 and not eof $read) { $count++; close $write; $new_name = "$file$count"; open $write, '>', $new_name or die $!; } } } Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. -- Damian Conway in "Perl Best Practices"
lesen: Wie frage ich & perlintro brian's Leitfaden für jedes Perl-Problem |