Thread Inhalt einer vom User hochgeladenen Textdatei in einer Listbox anzeigen (15 answers)
Opened by Newbie2008 at 2008-12-07 16:20

Newbie2008
 2008-12-10 20:39
#117063 #117063
User since
2008-12-05
26 Artikel
BenutzerIn
[default_avatar]
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/perl -w
use strict;
use Tk;

my %variable;
my $haupt = MainWindow->new();
frame ($haupt,%variable);
MainLoop;


sub frame {
        my ($haupt,%hash) = @_;

        my $frame_eingabe       = $haupt->Frame()->pack();
        my $frame_ausgabe       = $haupt->Frame()->pack();
        my $frame_button        = $haupt->Frame()->pack();
        my $frame_edit          = $haupt->Frame()->pack();

        my $Label_eingabe = $frame_eingabe->Label(
                -text =>'Bitte wählen Sie Ihre Ausgangs-Textdatei (txt):',
                )->pack(-side =>'left');

        my $Entry_eingabe = $frame_eingabe->Entry(
                -textvariable => \$hash{input},
        )->pack(-side => 'left');

        my $Button_eingabe = $frame_eingabe->Button(
                -text =>'Durchsuchen',
                -command => [\&eingabe, $haupt,\$hash{input}],
                )->pack(-side =>'left');



    my $Nachricht_lbl  = $frame_edit->Label(
                                -textvariable => \$hash{nachricht},
                                           )->pack();
    my $listbox = $frame_edit->Listbox(
                                -width    => 75,
                                -height   => 20,
                                             )->pack();


        my $Label_ausgabe = $frame_ausgabe->Label(
                -text =>'Unter welchem Namen / wo soll die Ausgabe-Textdatei gespeichert werden:',
                )->pack(-side =>'left');

        my $Entry_ausgabe = $frame_ausgabe->Entry(
                -textvariable => \$hash{output},
                )->pack(-side =>'left');

        my $Button_ausgabe = $frame_ausgabe->Button(
                -text =>'Durchsuchen',
                -command => [\&ausgabe, $haupt,\$hash{output}],
                )->pack(-side =>'left');


    my $Button_start = $frame_button->Button(
                                -text    => 'Ausfuehren',
                                -command => [\&einlesen,$listbox,\%hash])->pack();
}


sub einlesen {
    my ($list,$hashref) = @_;
    
    if(defined $hashref->{input} && defined $hashref->{output}){
        if(open(my $fh,'<',$hashref->{input}) && 
           open(my $w_fh,'>',$hashref->{output})){
            while(my $line = <$fh>){
                print $w_fh $. . " " . $line;
                chomp $line;
                $list->insert('end', $. . " " . $line);
            }
            close $fh;
            close $w_fh;
            $hashref->{message} = 'Aktion erfolgreich';
        }
        else{
            $hashref->{message} = 'Aktion nicht erfolgreich';
        }
    }
    else{
        $hashref->{message} = 'Bitte Eingabe- und Ausgabedatei festlegen';
    }
}


sub eingabe{
    my ($haupt,$var_ref) = @_;    
    my $Dateityp = [['Text files','.txt'],['Text files','.TXT']];
    $$var_ref = $haupt->getOpenFile(-filetypes => $Dateityp);
}

sub ausgabe{
    my ($haupt,$var_ref) = @_;
    my $Dateityp = [['Text files','.txt'],['Text files','.TXT']];
    $$var_ref = $haupt->getSaveFile(-filetypes => $Dateityp);
}

View full thread Inhalt einer vom User hochgeladenen Textdatei in einer Listbox anzeigen