Thread Textdatei einlesen, ändern, neue erstellen: open (DATEI, "text.txt") (30 answers)
Opened by Gast at 2003-09-16 00:10

Barbara
 2003-09-16 16:03
#43486 #43486
User since
2003-09-16
2 Artikel
BenutzerIn
[default_avatar]
Hallo,

Danke, dass Ihr mir Eure Hilfe anbietet.

Hier meine Fehlermeldung:


Code: (dl )
1
2
3
4
5
6
7
8
C:\Perl\bin\CGP02>aufg1.pl
Tk::Error: Datei kann nicht geöffnet werden at C:\Perl\bin\CGP02\aufg1.pl line 3
7.
[\&main::action]
Tk callback for .frame.button
Tk:: at C:/Perl/site/lib/Tk.pm line 228
Tk::Button::butUp at C:/Perl/site/lib/Tk/Button.pm line 111
(command bound to event)


Hier mein Skript:

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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/local/bin/perl -w

use strict;
use Tk;
my $haupt = new MainWindow;

my $links = $haupt->Frame();
$links->Label(-text=> "Geben Sie die Namen der Ausgangsdatei und der Ausgabedatei ein: ")->pack();

my $ausgangsdatei = $links->Entry();
$ausgangsdatei->pack();

my $ausgabedatei = $links->Entry();
$ausgabedatei->pack();

my $schalter1 = $links->Button(
-text=>"START",
-command=> \&action
)->pack();

my $schalter2 = $links->Button(
-text=> "Exit",
-command => [$haupt => 'destroy']
)->pack;

my $rechts = $haupt->Frame();
$rechts->Label(-text=> "Ausgabe:")->pack();
my $daten = $rechts->Listbox();

$links->pack(-side => "left");
$rechts -> pack(-side => "right");

MainLoop();

sub action
{
open(DATEI,"<$ausgangsdatei")
or die "Datei kann nicht ge\x94ffnet werden";

open(NEU, ">$ausgabedatei")
or die "Datei kann nicht ge\x94ffnet werden";

undef$/;
my $text = <DATEI>;
print "\n\n$text\n";

$text =~s/\bsie\b/Sie/g;

print NEU $text;

print "\n\n$text\n";

close(DATEI);
close(NEU);
}



Hier mein Skript:
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/local/bin/perl -w

use strict;
use Tk;
my $haupt = new MainWindow;

my $links = $haupt->Frame();
$links->Label(-text=> "Geben Sie die Namen der Ausgangsdatei und der Ausgabedatei ein: ")->pack();

my $ausgangsdatei = $links->Entry();
$ausgangsdatei->pack();

my $ausgabedatei = $links->Entry();
$ausgabedatei->pack();

my $schalter1 = $links->Button(
-text=>"START",
-command=> \&action
)->pack();

my $schalter2 = $links->Button(
-text=> "Exit",
-command => [$haupt => 'destroy']
)->pack;

my $rechts = $haupt->Frame();
$rechts->Label(-text=> "Ausgabe:")->pack();
my $daten = $rechts->Listbox();

$links->pack(-side => "left");
$rechts -> pack(-side => "right");

MainLoop();

sub action
{
open(DATEI,"<$ausgangsdatei")
or die "Datei kann nicht ge\x94ffnet werden";

open(NEU, ">$ausgabedatei")
or die "Datei kann nicht ge\x94ffnet werden";

undef$/;
my $text = <DATEI>;
.
.
.
.
.
.
}


Wie das mit dem Einfügen der Nummerierung funkt weiß ich auch noch nicht!
Grüße Barb

Bearbeitet von Crian: CODE-Blöcke hinzugefügt. (... und das Doppelposting entfernt.)\n\n

<!--EDIT|Crian|1064174189-->

View full thread Textdatei einlesen, ändern, neue erstellen: open (DATEI, "text.txt")