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
| #!/usr/bin/perl
use warnings;
use strict;
use Tk;
my ( $fichier_input, $fichier_output );
my $fenetre_principale = MainWindow->new( -title => 'Test de graph' );
my $LabelInput = $fenetre_principale->Label( -text => 'Quel fichier traiter ? : ' );
my $BoutonInput = $fenetre_principale->Button(
-text => 'input file',
-command => sub { $fichier_input = $fenetre_principale->getOpenFile(); }
);
my $AfficheInput = $fenetre_principale->Label( -textvariable => \$fichier_input );
my $LabelOutput = $fenetre_principale->Label( -text => 'Quel nom en sortie ? : ' );
my $BoutonOutput = $fenetre_principale->Button(
-text => 'output file',
-command => sub {
$fichier_output = $fenetre_principale->getSaveFile( -initialfile => "FichierResutat.txt" );
},
);
my $AfficheOutput = $fenetre_principale->Label( -textvariable => \$fichier_output );
my $BoutonGO = $fenetre_principale->Button(
-text => "GO !",
-command => \&feu,
);
# Utilisation de grid pour la disposition des éléments
$LabelInput->grid( $BoutonInput, $AfficheInput, qw/ -sticky nsew / );
$LabelOutput->grid( $BoutonOutput, $AfficheOutput, qw/ -sticky nsew / );
$BoutonGO->grid( '-', qw/ -sticky nsew -pady 25/ );
MainLoop;
sub feu {
unless ( defined $fichier_input ) {
print "Pas de fichier input\n";
return;
}
unless ( defined $fichier_output ) {
print "Pas de fichier output\n";
return;
}
print "input : $fichier_input\noutput : $fichier_output\n";return;
open( IN, '<:encoding(utf8)', $fichier_input ) or die("Impossible de lire le fichier $fichier_input\n");
open( OUT, '>:encoding(utf8)', $fichier_output ) or die("Impossible de d'ecrire dans le fichier $fichier_output\n");
while ( my $line = <IN> ) {
chomp $line;
# Ton traitement, et ecrit proprement
}
close IN;
close OUT;
return;
} |
Partager