Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Perl script for scanning files

Reply
Thread Tools

Perl script for scanning files

 
 
Anton van der Steen
Guest
Posts: n/a
 
      12-02-2005
Hey guys,

Here a script for searching for words or phrases in files.
The lines cna be shown with one press on the button.

I have tested this program on a text file of 2 Gb and it took 8 minutes to
present a result scannin on the letter 'e'.

I use Perl from www.ActiveState.com .
No extra Perl Modules have to be installed.

Success and have fun with. I use it a lot.

Scoon


#!/perl/bin/perl
use Tk;

my $mw = new MainWindow; # Main Window

my $frm_name = $mw -> Frame() -> pack();
my $lab1 = $frm_name -> Label(-text=>"Phrase :") -> pack();
my $ent1 = $frm_name -> Entry(-width=>100) -> pack();

my $lab2=$frm_name->Label(-text=>"File :")->pack();
my $ent2=$frm_name->Entry(-width=>100)->pack();


my $but1 = $mw -> Button(-text=>"Count Appearance Phrase", -command
=>\&push_button1) -> pack();

my $but2 = $mw -> Button(-text=>"Show text", -command =>\&push_button2) ->
pack();

my $but3 = $mw -> Button(-text=>"Clear Text Area", -command
=>\&push_button3) -> pack();

#Text Area
my $txt = $mw -> Text(-width=>130, -height=>40) -> pack();


MainLoop;

sub push_button1 {

use Getopt::Std;

my $name1 = $ent1 -> get();
my $name2 = $ent2 -> get();
#$txt -> insert('end',"Hello, $name1, $name2");
@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 "Het woord is gevonden in het document\n";
#print "$file: $line\n" if (!$opt_1);
#$txt-> insert ('end', "$file, $line");

}

}
#print "$file" 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.");
#$txt-> insert ('0.0', "$file, $line");
close (FILE);
$i=0;

}


sub push_button2 {

use Getopt::Std;

my $name1 = $ent1 -> get();
my $name2 = $ent2 -> get();
#$txt -> insert('end',"Hello, $name1, $name2");
@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 "Het woord is gevonden in het document\n";
#print "$file: $line\n" if (!$opt_1);
#$txt-> insert ('end', "$file, $line");
$txt-> insert ('end', "$line");
}

}
#print "$file" if ($opt_1);
#print "Het woord $pattern is $i keer gevonden\n";


#$txt-> insert ('end',"Het woord $pattern is $i keer gevonden in bestand
$file.");
#$txt-> insert ('end', "$file, $line");
close (FILE);
$i=0;

}

}


sub push_button3 {
$txt-> delete ('0.0', 'end');


}

};


 
Reply With Quote
 
 
 
 
usenet@DavidFilmer.com
Guest
Posts: n/a
 
      12-02-2005
Anton van der Steen wrote:
> No extra Perl Modules have to be installed.


> #!/perl/bin/perl
> use Tk;


FWIW, Tk is not a standard module (at least not in my Perl 5.8.4
distribution).

 
Reply With Quote
 
 
 
 
Paul Lalli
Guest
Posts: n/a
 
      12-02-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> Anton van der Steen wrote:
> > No extra Perl Modules have to be installed.

>
> > #!/perl/bin/perl
> > use Tk;

>
> FWIW, Tk is not a standard module (at least not in my Perl 5.8.4
> distribution).


Anton van der Steen wrote:
> > I use Perl from www.ActiveState.com .


Tk *is* standard in ActiveState's distribution.

Paul Lalli

 
Reply With Quote
 
Raghuramaiah Gompa
Guest
Posts: n/a
 
      01-21-2006
In article <(E-Mail Removed) .com>,
Paul Lalli <(E-Mail Removed)> wrote:
>(E-Mail Removed) wrote:
>> Anton van der Steen wrote:
>> > No extra Perl Modules have to be installed.

>>
>> > #!/perl/bin/perl
>> > use Tk;

>>
>> FWIW, Tk is not a standard module (at least not in my

>Perl 5.8.4
>> distribution).

>
>Anton van der Steen wrote:
>> > I use Perl from www.ActiveState.com .

>
>Tk *is* standard in ActiveState's distribution.
>
>Paul Lalli
>


I wonder whether this code can be modifed to "highlight
all instances of text between quotes". For example, if
the previous
sentence is in a file, the code should show the line with
red color for "highlight all instances of text between
quotes". Is it possible? .. Raghu
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
CGI: Execute a perl script inside another perl script xdarcos@hotmail.com Perl Misc 20 01-18-2005 12:33 PM
Execute another perl script from my perl script Petterson Mikael Perl Misc 3 01-05-2005 01:31 PM
problem calling perl script from SOAP server perl script pj Perl Misc 3 04-09-2004 10:23 PM
Perl Help - Windows Perl script accessing a Unix perl Script dpackwood Perl 3 09-30-2003 02:56 AM
How to make Perl Script "POST" call from another Perl Script??? Wet Basement Perl 1 07-15-2003 10:25 PM



Advertisments