Re: Problem with Perl/Tk
From: Ben Morrow (usenet_at_morrow.me.uk)
Date: 02/16/04
- Next message: Paul Lalli: "Re: OPEN( , Get , or slurping problem"
- Previous message: ctcgag_at_hotmail.com: "Re: do not reload"
- In reply to: Orion93: "Problem with Perl/Tk"
- Next in thread: Orion93: "Re: Problem with Perl/Tk"
- Reply: Orion93: "Re: Problem with Perl/Tk"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 16 Feb 2004 20:34:26 +0000 (UTC)
Orion93 <orion93@club-internet.fr> wrote:
use strict;
use warnings;
> use Tk;
>
> $main = MainWindow -> new;
my $main = ...;
> $main->title("Test 1");
> $libelF=$main->Label(-text=>'Chemin:')->pack();
my $libelF = ...;
&c.
> $montantF->Entry(-textvariable=>\$nomFic)->pack(-padx=>5);
> $valid=$main->Button(-text=>'Ok',-command=>\&recupPages)->pack(-
> side=>'left', expand=>1);
It would be a lot easier to see what is going on if you put some
whitespace in here; also, you never set $montantF:
my $nomFic;
my $montantF = $main->Entry (-textvariable => \$nomFic)
->pack (-padx => 5);
my $valid = $main->Button(-text => 'Ok', -command => \&recupPages)
->pack (-side => 'left', -expand => 1);
As an aside, I *really* hate apps that call buttons 'Ok': not only is it
inconsistent with every OS I've ever used, it's also Wrong. It's an
abbreviation, so it's spelt 'OK'.
> $end=$main->Button(-text=>'Fermer',-command=>sub {exit})->pack(-
> side=>'right', expand=>1);
> MainLoop();
>
> sub recupPages
> {
> my $rep= $montantF->get();
> my $result = shift;
> open(F,'$nomFic');
> open(SORTIE,'$result');
Use lexical filehandles: they close automatically, which makes your life
easier. Check the return value of open: yes, *every* time. Those single
quotes won't interpolate, so you're trying to open a file called
'$nomFic'. You don't need quotes at all.
open my $F, $nomFic or die "can't open $nomFic: $!";
open my $SORTIE, $result or die "can't open $result: $!";
> $i = 0;
> while(<F>)
> {
> $i ++;
> }
> print SORTIE " $nomFic $i\n";
> close F;
> close SORTIE;
> }
Sort out your indentation: it makes things much easier:
sub recupPages {
my $rep = $montantF->get();
my $result = shift;
I'm not sure what you think this does, but I doubt it's what you mean.
Do you not just mean
my $result = $montantF->get();
? Or, indeed, just use $nomFic, since you've set that up to contain the
value of the entry box... no, hang on, $nomFic is the input file. Where
do you want the name of the output file to come from?
open my $F...
...
while (<$F>) {
$i++;
}
Or, neater:
$i++ while <$F>;
Or use $. instead of $i:
1 while <$F>;
print $SORTIE " $nomFic $.\n";
See perldoc perlvar.
print $SORTIE " $nomFic $i\n";
# no need to close the FHs: they will close at the end of the scope.
}
> my $emplacement = $nomFic;
> my $ficResultat = "e:\\result.txt";
> recupPages($_, $ficResultat) for glob '$nomFic';
I'm not sure when you want this to execute, but as things stand it
won't, ever. MainLoop never returns, so Perl will never get here. If you
want it to be executed when the OK button is pressed, it needs to go
inside recupPages; if you want it to be executed at the end of the
program (ie. when the Fermer button is pressed) it needs to go in an END
block:
END {
my $emplacement = $nomFic; # why? you never use this variable.
my $ficResultat = 'e:/result.txt'; # yes, use / even on win32
recupPages($_, $ficResultat) for glob $nomFic;
# again, the '' quotes won't interpolate the variable.
}
I get the feeling you're not entirely clear about what you want this
program to do... or, at any rate, *I'm* not.
Ben
-- 'Deserve [death]? I daresay he did. Many live that deserve death. And some die that deserve life. Can you give it to them? Then do not be too eager to deal out death in judgement. For even the very wise cannot see all ends.' :-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-: ben@morrow.me.uk
- Next message: Paul Lalli: "Re: OPEN( , Get , or slurping problem"
- Previous message: ctcgag_at_hotmail.com: "Re: do not reload"
- In reply to: Orion93: "Problem with Perl/Tk"
- Next in thread: Orion93: "Re: Problem with Perl/Tk"
- Reply: Orion93: "Re: Problem with Perl/Tk"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|