tie my @A_cur_file_data, 'Tie::File', $cur_entrykey_path, recsep => "\r\n", discipline => ':encoding(UTF-8)' or die $!;
1 2 3
$A_cur_file_data[12] = "Juhu"; $A_cur_file_data[13] = "Hallo"; $A_cur_file_data[14] = "Welt!";
1
2
3
4
% perl -wE'use Tie::File;tie my @A, "Tie::File", "blah.txt", discipline => ":encoding(UTF-8):crlf" or die $!; $A[2] = "Hallo";$A[4] = "Welt";'
% od -A n -c blah.txt
\r \n \r \n H a l l o \r \r \n W e l t
\r \n \r \n
1
2
3
4
5
% rm blah.txt
% perl -wE'use Tie::File;tie my @A, "Tie::File", "blah.txt", discipline => ":encoding(UTF-8)", recsep => "\r\n" or die $!; $A[2] = "Hallo";$A[4] = "Welt";'
% od -A n -c blah.txt
\r \n \r \n H a l l o \r \n \r \n W e l
t \r \n
1 2 3 4 5 6 7 8 9 10 11
#!/usr/bin/perl use Tie::File; use utf8; tie my @A, 'Tie::File', "blah.txt", recsep => "\r\n", discipline => ':encoding(UTF-8)' or die $!; $A[3] = 'Hallo'; $A[4] = 'welt'; $A[12] = 'Sehr gut Jürgen'; $A[13] = 'äüöß'; $A[14] = 'Was mache ich falsch?';
1 2 3 4 5 6 7 8 9
open(FH,"blah.txt") || die $!; @A = <FH>; close(FH); # mach Sachen mit Array... open(FH,">blah.txt") || die $!; print FH @A; close(FH)
JürgenBis zu welcher "Zeilenanzahl" kann ich den Konstrukt sinnvoll verwenden?
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#!/usr/bin/perl use warnings; use strict; my $filename = "myfile"; open(my $fh, "<", $filename); my $nr = 0; while (my $l = <$fh>) { $nr++; chomp($l); print "$nr.\t$l\n"; } close($fh);
1 2 3 4 5
open( my $fhi, '<', $datei ) or die "Fehler bei open: $!"; # lesend öffnen while(<$fhi>) { # mach was mit $_ } close $fhi;