A
anton.vandersteen
Hello Perl addicts,
This is my sollution:
#!/perl/bin/perl
#This programme is written by Anton van der Steen
#Email adres: (e-mail address removed)
use Tk;
use File::Find;
my $mw = new MainWindow; # Main Window
$mw->title("Search Engine Version 2.0 by Stone Logic Systems");
######################################################################
$mw->configure(-menu => my $menubar = $mw->Menu);
my $filemenu = $menubar->cascade(-label => "~File",
-tearoff => 1);
my $execute_sql_statement= $menubar->cascade(-label => "Count
~Phrase",
-tearoff=>1);
my $save_result_to_file = $menubar->cascade(-label => "~Show Text",
-tearoff=>1);
my $clear_text_area = $menubar->cascade(-label => "~Clear Result Set",
-tearoff=>1);
my $create_pdf = $menubar->cascade(-label => "~Export to File",
-tearoff=>1);
my $create_excel = $menubar->cascade(-label=> "Find File",
-tearoff=>1);
#my $create_xml = $menubar->cascade(-label=> "Export to XML",
# -tearoff=>1);
my $helpmenu = $menubar->cascade(-label => "~Help",
-tearoff => 1);
$filemenu->command(-label => "E~xit",
-command => sub{$mw->destroy});
$execute_sql_statement->command(-label => "Count ~Phrase",
-command=> sub{push_button1()});
$save_result_to_file->command(-label =>"~Show Text",
-command=> sub{push_button2()});
$clear_text_area->command(-label => "~Clear Result Set",
-command=> sub {push_button3()});
$create_pdf->command(-label => "~Export to File",
-command=> sub {push_button4()});
$create_excel->command(-label =>"Find File",
-command=> sub {push_button5()}) ;
#$create_xml->command(-label =>"Export to XML",
#-command=> sub {XML()});
$helpmenu->command(-label => "~Help Contents",
-command => sub{showhelp()});
######################################################################
my $frm_name = $mw -> Frame() -> pack();
my $lab1 = $frm_name -> Label(-text=>"Phrase :", -font => '-adobe-
helvetica-bold-r-normal--11-120-75-75-p-70-*-1') -> pack();
my $ent1 = $frm_name -> Entry(-width=>100, -borderwidth=>2) -> pack();
$ent1->configure(-font => '-adobe-helvetica-bold-r-
normal--11-120-75-75-p-70-*-1');
my $lab2=$frm_name->Label(-text=>"Search in File :", -font => '-adobe-
helvetica-bold-r-normal--11-120-75-75-p-70-*-1')->pack();
my $ent2=$frm_name->Entry(-width=>100)->pack();
$ent2->configure(-font => '-adobe-helvetica-bold-r-
normal--12-120-75-75-p-70-*-1');
my $lab3=$frm_name->Label(-text=>"Export to file :", -font => '-adobe-
helvetica-bold-r-normal--11-120-75-75-p-70-*-1')->pack();
my $ent3=$frm_name->Entry(-width=>100)->pack();
$ent3->configure(-font => '-adobe-helvetica-bold-r-
normal--12-120-75-75-p-70-*-1');
#my $but1 = $mw -> Button(-text=>"Count Appearance Phrase", -command =>
\&push_button1, -background=>"green",
# -font => '-adobe-helvetica-bold-r-normal--11-120-75-75-p-70-*-1') ->
pack();
#my $but2 = $mw -> Button(-text=>"Show text", -command =>
\&push_button2, -background=>"yellow",
# -font => '-adobe-helvetica-bold-r-normal--11-120-75-75-p-70-*-1') ->
pack();
#my $but3 = $mw -> Button(-text=>"Clear Text Area", -command =>
\&push_button3, -background=>"orange",
# -font => '-adobe-helvetica-bold-r-normal--11-120-75-75-p-70-*-1') ->
pack();
#my $but4 = $mw -> Button(-text=>"Save result to file", -command =>
\&push_button4, -background=>"cyan",
# -font => '-adobe-helvetica-bold-r-normal--11-120-75-75-p-70-*-1') ->
pack();
#Text Area
my $txt = $mw->Scrolled( 'Text' , -scrollbars=>'se' , -wrap=>
'none',);
$txt->configure(-width=>120, -height=>20, -font => '-adobe-helvetica-
bold-r-normal--14-120-75-75-p-70-*-1');
$txt->pack();
MainLoop;
sub push_button1 {
use Getopt::Std;
my $name1 = $ent1 -> get();
my $name2 = $ent2 -> get();
@ARGV= ($name1, $name2);
#print @ARGV;
$i=0;
my $pattern = shift @ARGV;
foreach $file (@ARGV)
{
open (FILE, $file);
while ($line = <FILE>)
{
if ($line =~m"$pattern")
{
$i++;
last if ($opt_1);
}
}
#print "The phrase $pattern is $i times found!!\n";
$txt-> insert ('0.0',"The phrase $pattern is $i times found in file
$file.\n");
close (FILE);
$i=0;
}
sub push_button2 {
use Getopt::Std;
my $name1 = $ent1 -> get();
my $name2 = $ent2 -> get();
@ARGV= ($name1, $name2);
$i=0;
my $pattern = shift @ARGV;
foreach $file (@ARGV)
{
open (FILE, $file);
while ($line = <FILE>)
{
if ($line =~m"$pattern")
{
$i++;
last if ($opt_1);
$txt-> insert ('end', "$line\n");
#print "$line\n";
}
}
close (FILE);
$i=0;
}
}
sub push_button3 {
$txt-> delete ('0.0', 'end');
}
sub push_button4 {
use Getopt::Std;
my $name1 = $ent1 -> get();
my $name2 = $ent2 -> get();
my $file_out = $ent3 -> get();
@ARGV= ($name1, $name2);
$i=0;
my $pattern = shift @ARGV;
open(OUT,">$file_out");
foreach $file (@ARGV)
{
open (FILE, $file);
while ($line = <FILE>)
{
if ($line =~m"$pattern")
{
$i++;
last if ($opt_1);
print OUT "$line\n";
}
}
close (FILE);
$i=0;
}
close(OUT);
}
}
sub push_button5{
find(\&push_button6, "c:\\")
}
sub push_button6 {
use Getopt::Std;
use File::Find;
my $a = $ent1 -> get();
if (/\.$a$/) # ((/\.zip$/) ||
{ #print "$File::Find::name\n";
$txt-> insert ('end', "$File::Find::name\n");
}
}
;
Have fun.....
This is my sollution:
#!/perl/bin/perl
#This programme is written by Anton van der Steen
#Email adres: (e-mail address removed)
use Tk;
use File::Find;
my $mw = new MainWindow; # Main Window
$mw->title("Search Engine Version 2.0 by Stone Logic Systems");
######################################################################
$mw->configure(-menu => my $menubar = $mw->Menu);
my $filemenu = $menubar->cascade(-label => "~File",
-tearoff => 1);
my $execute_sql_statement= $menubar->cascade(-label => "Count
~Phrase",
-tearoff=>1);
my $save_result_to_file = $menubar->cascade(-label => "~Show Text",
-tearoff=>1);
my $clear_text_area = $menubar->cascade(-label => "~Clear Result Set",
-tearoff=>1);
my $create_pdf = $menubar->cascade(-label => "~Export to File",
-tearoff=>1);
my $create_excel = $menubar->cascade(-label=> "Find File",
-tearoff=>1);
#my $create_xml = $menubar->cascade(-label=> "Export to XML",
# -tearoff=>1);
my $helpmenu = $menubar->cascade(-label => "~Help",
-tearoff => 1);
$filemenu->command(-label => "E~xit",
-command => sub{$mw->destroy});
$execute_sql_statement->command(-label => "Count ~Phrase",
-command=> sub{push_button1()});
$save_result_to_file->command(-label =>"~Show Text",
-command=> sub{push_button2()});
$clear_text_area->command(-label => "~Clear Result Set",
-command=> sub {push_button3()});
$create_pdf->command(-label => "~Export to File",
-command=> sub {push_button4()});
$create_excel->command(-label =>"Find File",
-command=> sub {push_button5()}) ;
#$create_xml->command(-label =>"Export to XML",
#-command=> sub {XML()});
$helpmenu->command(-label => "~Help Contents",
-command => sub{showhelp()});
######################################################################
my $frm_name = $mw -> Frame() -> pack();
my $lab1 = $frm_name -> Label(-text=>"Phrase :", -font => '-adobe-
helvetica-bold-r-normal--11-120-75-75-p-70-*-1') -> pack();
my $ent1 = $frm_name -> Entry(-width=>100, -borderwidth=>2) -> pack();
$ent1->configure(-font => '-adobe-helvetica-bold-r-
normal--11-120-75-75-p-70-*-1');
my $lab2=$frm_name->Label(-text=>"Search in File :", -font => '-adobe-
helvetica-bold-r-normal--11-120-75-75-p-70-*-1')->pack();
my $ent2=$frm_name->Entry(-width=>100)->pack();
$ent2->configure(-font => '-adobe-helvetica-bold-r-
normal--12-120-75-75-p-70-*-1');
my $lab3=$frm_name->Label(-text=>"Export to file :", -font => '-adobe-
helvetica-bold-r-normal--11-120-75-75-p-70-*-1')->pack();
my $ent3=$frm_name->Entry(-width=>100)->pack();
$ent3->configure(-font => '-adobe-helvetica-bold-r-
normal--12-120-75-75-p-70-*-1');
#my $but1 = $mw -> Button(-text=>"Count Appearance Phrase", -command =>
\&push_button1, -background=>"green",
# -font => '-adobe-helvetica-bold-r-normal--11-120-75-75-p-70-*-1') ->
pack();
#my $but2 = $mw -> Button(-text=>"Show text", -command =>
\&push_button2, -background=>"yellow",
# -font => '-adobe-helvetica-bold-r-normal--11-120-75-75-p-70-*-1') ->
pack();
#my $but3 = $mw -> Button(-text=>"Clear Text Area", -command =>
\&push_button3, -background=>"orange",
# -font => '-adobe-helvetica-bold-r-normal--11-120-75-75-p-70-*-1') ->
pack();
#my $but4 = $mw -> Button(-text=>"Save result to file", -command =>
\&push_button4, -background=>"cyan",
# -font => '-adobe-helvetica-bold-r-normal--11-120-75-75-p-70-*-1') ->
pack();
#Text Area
my $txt = $mw->Scrolled( 'Text' , -scrollbars=>'se' , -wrap=>
'none',);
$txt->configure(-width=>120, -height=>20, -font => '-adobe-helvetica-
bold-r-normal--14-120-75-75-p-70-*-1');
$txt->pack();
MainLoop;
sub push_button1 {
use Getopt::Std;
my $name1 = $ent1 -> get();
my $name2 = $ent2 -> get();
@ARGV= ($name1, $name2);
#print @ARGV;
$i=0;
my $pattern = shift @ARGV;
foreach $file (@ARGV)
{
open (FILE, $file);
while ($line = <FILE>)
{
if ($line =~m"$pattern")
{
$i++;
last if ($opt_1);
}
}
#print "The phrase $pattern is $i times found!!\n";
$txt-> insert ('0.0',"The phrase $pattern is $i times found in file
$file.\n");
close (FILE);
$i=0;
}
sub push_button2 {
use Getopt::Std;
my $name1 = $ent1 -> get();
my $name2 = $ent2 -> get();
@ARGV= ($name1, $name2);
$i=0;
my $pattern = shift @ARGV;
foreach $file (@ARGV)
{
open (FILE, $file);
while ($line = <FILE>)
{
if ($line =~m"$pattern")
{
$i++;
last if ($opt_1);
$txt-> insert ('end', "$line\n");
#print "$line\n";
}
}
close (FILE);
$i=0;
}
}
sub push_button3 {
$txt-> delete ('0.0', 'end');
}
sub push_button4 {
use Getopt::Std;
my $name1 = $ent1 -> get();
my $name2 = $ent2 -> get();
my $file_out = $ent3 -> get();
@ARGV= ($name1, $name2);
$i=0;
my $pattern = shift @ARGV;
open(OUT,">$file_out");
foreach $file (@ARGV)
{
open (FILE, $file);
while ($line = <FILE>)
{
if ($line =~m"$pattern")
{
$i++;
last if ($opt_1);
print OUT "$line\n";
}
}
close (FILE);
$i=0;
}
close(OUT);
}
}
sub push_button5{
find(\&push_button6, "c:\\")
}
sub push_button6 {
use Getopt::Std;
use File::Find;
my $a = $ent1 -> get();
if (/\.$a$/) # ((/\.zip$/) ||
{ #print "$File::Find::name\n";
$txt-> insert ('end', "$File::Find::name\n");
}
}
;
Have fun.....