#!/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); }