This program is suppose to only display one name and number after the buttom is pressed. But the problem is it only displays the first name and number after the button is pressed. It won't display any other names or numbers but the first line. The program is not reading each line one at a time per button press. Only continue to display the first line in the file after the button is pressed. All help will be graceful!
[code=perl tk]
#!/usr/bin/perl -w
require Tk;
use Tk ':eventtypes';
use Tk;
my $mw = MainWindow->new();
open (FILE, "new.txt") || die "Can't open File.txt: $!\n";
$raw_data = <FILE>;
foreach $_ ($raw_data)
{
chomp ($_);
($c_name, $desricpt_info) = split(/\|/, $_);
$mw->Button (-text=>"two strings",
-command=>[\&printstrings, $_])
->pack(-side=>"left");}
$mw->Label(-textvariable=>\ $user)->pack();
sub printstrings
{
$user .= "the name $c_name $desricpt_info\ n";
}
MainLoop();
[/code]
[code=perl tk]
#!/usr/bin/perl -w
require Tk;
use Tk ':eventtypes';
use Tk;
my $mw = MainWindow->new();
open (FILE, "new.txt") || die "Can't open File.txt: $!\n";
$raw_data = <FILE>;
foreach $_ ($raw_data)
{
chomp ($_);
($c_name, $desricpt_info) = split(/\|/, $_);
$mw->Button (-text=>"two strings",
-command=>[\&printstrings, $_])
->pack(-side=>"left");}
$mw->Label(-textvariable=>\ $user)->pack();
sub printstrings
{
$user .= "the name $c_name $desricpt_info\ n";
}
MainLoop();
[/code]
Comment