Leser: 23
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
use strict; use warnings; my ($new,$file) = ('new.txt',shift); my @arr; die "Usage: <script> <file>\n" unless($file); open (FL,$file); @arr = <FL>; foreach my $line (@arr) { $line =~ s.\n..; $line .= "\n" if($line); open(NW,">>$new"); print NW $line; close NW; } close FL; print "[*] opening file\n[*] removing newlines\n[*] write new file\n[*] done\n\n";
ie "Usage: <script> <file>\n" unless($file);
1 2 3 4 5 6 7 8 9
# Lesen open my $fh, '<', $filename or die "$filename: $!\n"; # ... close $fh; # Schreiben open my $wh, '>', $filename or die "$filename: $!\n"; print $wh "Hello World\n" or die "print to $filename: $!\n"; close $wh or die "close $filename: $!\n";
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
#!/user/bin/perl # Script zum entfernen von mehrfachen Zeilenumbrüchen. use strict; use warnings; my $file=shift(@ARGV); my $new='new.txt'; die "Usage: <script> <file>\n" unless($file); open(my $nw,'>', $new) or die("Error open $new ($!)\n"); open (my $fl,$file) or die("Error open $file ($!)\n"); while(my $line=<$fl>) { chomp($line); $line .= "\n" if($line); print $nw $line; } close $fl; close $nw; print "[*] opening file\n[*] removing newlines\n[*] write new file\n[*] done\n\n";