Dear All,
I have written a script, which has to enter the file path (Paths
), in between the text. For this I have used below approach.
1) I divide the file in two parts, in which file path(s) has to be inserted.
-> Here @File_Part1 stores the first prart of file.
-> @File_Part2 stores the second part of file.
2) Then script will capture the file path entry into @File_Parth array.
3) Now I will insert the @File_Path array in between @File_Part1 and
@File_Part2, to achive our goal.
But the problem is, The widget is diplaying(inserting) only last file
pathselected with Tk::Pathenty. But my aim is to insert the number of file
path as selected with Tk::PathEntry tk module.
Plese help me to overcome this. Please find the code below for your kind
reference.
#!/usr/bin/perl -w
use Tk;
use strict;
use Tk::PathEntry;
use Cwd;
our($filename,$secondfile, $info,$path,$data,@File_Path);
$filename = "file.txt";
$secondfile = "secondfile.txt";
$path = cwd();
my @File_Part1;
my @File_Part2;
my $mw = MainWindow->new;
# Create necessary widgets
my $f = $mw->Frame->pack(-side => 'top', -fill => 'x');
#$f->Label(-text => "Filename:")->pack(-side => 'left', -anchor => 'w');
#$f->Entry(-textvariable => \$filename)->
pack(-side => 'left', -anchor => 'w', -fill => 'x', -expand => 1);
$f->Button(-text => "Exit", -command => sub { exit; } )->
pack(-side => 'right');
# Add file path.
$f->PathEntry( -textvariable=>\$path )->pack;
$f->Label( -textvariable=>\$path, -foreground=>'blue' )->pack(-side =>
'left');
$f->Button( -text=>'Capture', -command=> \&Capture )->pack(-side =>
'left');
$f->Button(-text => "Save", -command => \&save_file)->
pack(-side => 'right', -anchor => 'e');
$f->Button(-text => "Load", -command => \&load_file)->
pack(-side => 'right', -anchor => 'e');
$f->Button(-text => "Complete", -command => \&Complete)->
pack(-side => 'right', -anchor => 'e');
$mw->Label(-textvariable => \$info, -relief => 'ridge')->
pack(-side => 'bottom', -fill => 'x');
my $t = $mw->Scrolled("Text")->pack(-side => 'bottom',
-fill => 'both', -expand => 1);
MainLoop;
# load_file checks to see what the filename is and loads it if possible
sub load_file {
$info = "Loading file '$filename'...";
# $t->delete("1.0", "end");
## Copying first file data and storing in an Array, @File_Part1
if (!open(FH1, "$filename")) {
$t->insert("end", "ERROR: Could not open $filename\n");
return;
}
@File_Part1 = <FH1>;
close(FH1);
## Copying Second file data and storing in an Array, @File_Part2
if (!open(FH2, "$secondfile")) {
$t->insert("end", "ERROR: Could not open $filename\n");
return;
}
@File_Part2 = <FH2>;
close(FH2);
}
## This function will the capture the file path entrires and store into an
array, @File_Part.
sub Capture {
@File_Path =$path;
#open (FILE,">>f1.txt") or die "Can't open $!";
#foreach (@File_Path) {
# print FILE $_;
# $t -> insert ("end", $_);
#}
}
## This widget display the Result on Text widget
sub Complete {
foreach (@File_Part1) {
$t -> insert ("end", "$_\n");
}
foreach (@File_Path) {
$t -> insert ("end", "$_\n");
}
foreach (@File_Part2) {
$t -> insert ("end", "$_\n");
}
}
# save_file saves the file using the filename in the Entry box.
sub save_file {
$info = "Saving '$filename'";
open (FH, ">$filename");
print FH $t->get("1.0", "end");
$info = "Saved.";
}
_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs