Thread Problem mit Zeilenausgabe
(7 answers)
Opened by Trommelwirbel at 2012-05-22 10:27
Setze den InputLineSeparator $/ richtig
Code (perl): (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 33 34 35 36 37 38 39 40 #!/usr/bin/perl use strict; use warnings; use File::Spec; my $ordner='source'; my $ausgabe='result'; opendir(my $dh,$ordner) or die("Error open $ordner ($!)\n"); while(my $file=readdir($dh)) { my $path=File::Spec->join($ordner,$file); next unless(-f $path); if(open(my $fh, '<', $path)) { local $/="ENDE\n"; while(my $block=<$fh>) { $block=~s/ENDE\s*$//; next unless($block); my ($name)=$block=~/^(.+?)\s+\d+/; next unless($name); my $out_path=File::Spec->join($ausgabe,$name); if(open(my $ofh, '>', $out_path)) { print $ofh $block; close($ofh); } else { warn("Error open $out_path ($!)\n") } } close($fh); } else { warn("Error open $path ($!)\n"); } } closedir($dh); |