A
Anton van der Steen
Hey guys,
Here is version 2.0 for scanning files.
I have added scrollbars to the text area and a function
to print OUT the result to a other file.
Below you will find the script.
I have tested it with Perl 5.8.6 from ActiveState.com,
bear this in mind.
Have fun.
Anton van der Steen, another perl addict
Eindhoven/The Netherlands/Europe
#!/perl/bin/perl
#Dit programma is geschreven door Anton van der Steen
#Email adres: (e-mail address removed)
use Tk;
my $mw = new MainWindow; # Main Window
$mw->title("Search Engine Version 2.0 by Stone Logic Systems");
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--11-120-75-75-p-70-*-1');
my $lab3=$frm_name->Label(-text=>"Save out 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--11-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=>150, -height=>35);
$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);
}
};
Here is version 2.0 for scanning files.
I have added scrollbars to the text area and a function
to print OUT the result to a other file.
Below you will find the script.
I have tested it with Perl 5.8.6 from ActiveState.com,
bear this in mind.
Have fun.
Anton van der Steen, another perl addict
Eindhoven/The Netherlands/Europe
#!/perl/bin/perl
#Dit programma is geschreven door Anton van der Steen
#Email adres: (e-mail address removed)
use Tk;
my $mw = new MainWindow; # Main Window
$mw->title("Search Engine Version 2.0 by Stone Logic Systems");
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--11-120-75-75-p-70-*-1');
my $lab3=$frm_name->Label(-text=>"Save out 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--11-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=>150, -height=>35);
$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);
}
};