Please help with a script, knoledge needed!

E

Eric Strunk

Hello all,

I don't have any knoledge of perl but i have a script what is running
on the server and doesn't do his job.

It has to search along a lot of files and find a word in a line.
If it finds the word only this line has to be displayed on the screen.
Then it has to search for the next same word in the same file.
If it doesn't find the next word in a line it has to go to the next
file and do the same again.

Until the first word in the file it works nice and even the printing
is fine. But it never find the next line what contain the same search
querie, instead it goes to the next file and find there the first word
and so on.

This is the search file with printing,
-------------------------------------------------------------
#!/usr/bin/perl

use strict;
use warnings;
use CGI;
use CGI::Carp ("fatalsToBrowser");
my $q = CGI->new;
my $zoek = $q->param("zoek");
chdir "/www/xxx.xxx.xxxxxx.xx/xxxx";
my @data_files = glob "*.*";

print CGI::header();
print CGI::start_html(" my searchengine");

print <<EOT;
<P><UL><BR><FONT SIZE=+1><B><I>Legenda:</I></B></FONT><P>
1 = Recordnummer<BR>
2 = Geslacht<BR>
3 = Naam en voornamen<BR>
4 = Geboorteplaats<BR>
5 = Geboortedatum<BR>
6 = Overlijdensdatum<BR>
7 = Recordnummer vader<BR>
8 = Recordnummer moeder<BR></UL><P><HR WIDTH=33% ALIGN=LEFT>
EOT


my $hits = 0;
foreach my $file ( @data_files ) {
if ( !open F, "<$file" ) {
warn "Could not open $file ($!)\n";
next;
}

my $found = 0;
while (<F>) {
if ( /$zoek/i ) {
$hits++;
print
"<pre><b>Bestandsnaam</b><br>\n<i>$file</i></PRE><br>\n";
print "<pre> 1 2 3
4 5 6
7 8</pre>" ; \
print "<pre>$_\n<br></PRE>";
last;
}
}
close F;
}

print "<h3>", $hits ? $hits : "Geen", " bestanden gevonden</H3>";

--------------------------------------------------------------------
This is it, can anyone help me please to get all the lines in one file
and go to the next file after that.

Kind regards
Eric.
 
M

Michael Budash

Eric Strunk said:
Hello all,

I don't have any knoledge of perl but i have a script what is running
on the server and doesn't do his job.

It has to search along a lot of files and find a word in a line.
If it finds the word only this line has to be displayed on the screen.
Then it has to search for the next same word in the same file.
If it doesn't find the next word in a line it has to go to the next
file and do the same again.

Until the first word in the file it works nice and even the printing
is fine. But it never find the next line what contain the same search
querie, instead it goes to the next file and find there the first word
and so on.

This is the search file with printing,
-------------------------------------------------------------
#!/usr/bin/perl

use strict;
use warnings;
use CGI;
use CGI::Carp ("fatalsToBrowser");
my $q = CGI->new;
my $zoek = $q->param("zoek");
chdir "/www/xxx.xxx.xxxxxx.xx/xxxx";
my @data_files = glob "*.*";

print CGI::header();
print CGI::start_html(" my searchengine");

print <<EOT;
<P><UL><BR><FONT SIZE=+1><B><I>Legenda:</I></B></FONT><P>
1 = Recordnummer<BR>
2 = Geslacht<BR>
3 = Naam en voornamen<BR>
4 = Geboorteplaats<BR>
5 = Geboortedatum<BR>
6 = Overlijdensdatum<BR>
7 = Recordnummer vader<BR>
8 = Recordnummer moeder<BR></UL><P><HR WIDTH=33% ALIGN=LEFT>
EOT


my $hits = 0;
foreach my $file ( @data_files ) {
if ( !open F, "<$file" ) {
warn "Could not open $file ($!)\n";
next;
}

my $found = 0;
while (<F>) {
if ( /$zoek/i ) {
$hits++;
print
"<pre><b>Bestandsnaam</b><br>\n<i>$file</i></PRE><br>\n";
print "<pre> 1 2 3
4 5 6
7 8</pre>" ; \
print "<pre>$_\n<br></PRE>";
last;

^^^^^^^^^^^^^^^^^^^
remove this line
}
}
close F;
}

print "<h3>", $hits ? $hits : "Geen", " bestanden gevonden</H3>";

--------------------------------------------------------------------
This is it, can anyone help me please to get all the lines in one file
and go to the next file after that.

Kind regards
Eric.

hth-
 
E

Eric Strunk

Cut out
----------------------------------------------------------
^^^^^^^^^^^^^^^^^^^
remove this line

cut out again ----------------------------------------------------

Great that's working the way it must work.

Many thanks for solving the problem, and thanks again.

Eric.
 
E

Eric Strunk

^^^^^^^^^^^^^^^^^^^
remove this line


hth-
Hello out there,

Still have a question.
Everytime a hit takes place it is putting header info above it.
$file and the line wit 12345678

How do i get it to print it once for a file, but only if found
something in the file.

Another cry
Eric.
 
M

Michael Budash

Still have a question.
Everytime a hit takes place it is putting header info above it.
$file and the line wit 12345678

How do i get it to print it once for a file, but only if found
something in the file.

while (<F>) {
my $hdrprinted;
if ( /$zoek/i ) {
$hits++;
unless ($hdrprinted) {
# print the header here
$hdrprinted++;
}
print "<pre>$_\n<br></PRE>\n";
}
}

hth-
 
E

Eric Strunk

while (<F>) {
my $hdrprinted;
if ( /$zoek/i ) {
$hits++;
unless ($hdrprinted) {
# print the header here
$hdrprinted++;
}
print "<pre>$_\n<br></PRE>\n";
}
}

hth-

It didn't work out still have all the headers i had before, put all
the code down here again.

#!/usr/bin/perl

use strict;
use warnings;
use CGI;
use CGI::Carp ("fatalsToBrowser");
my $q = CGI->new;
my $zoek = $q->param("zoek");
chdir "/xxx/xxx.xxx.xx/xxxxx";
my @data_files = glob "*.*";

print CGI::header();
print CGI::start_html("genealogische zoekmachine");

print <<EOT;
<P><UL><BR><FONT SIZE=+1><B><I>Legenda:</I></B></FONT><P>
1 = Recordnummer<BR>
2 = Geslacht<BR>
3 = Naam en voornamen<BR>
4 = Geboorteplaats<BR>
5 = Geboortedatum<BR>
6 = Overlijdensdatum<BR>
7 = Recordnummer vader<BR>
8 = Recordnummer moeder<BR></UL><P><HR WIDTH=33% ALIGN=LEFT>
EOT


my $hits = 0;
foreach my $file ( @data_files ) {
if ( !open F, "<$file" ) {
warn "Could not open $file ($!)\n";
next;
}
my $found = 0;
while (<F>) {
my $hdrprinted;
if ( /$zoek/i ) {
$hits++;
unless ($hdrprinted) {
print "<pre> test </pre>\n";

print"<pre><b>Bestandsnaam</b><br>\n<i>$file</i></PRE><br>\n";
print "<pre> 1 </pre>" ; \
$hdrprinted++;
}
print "<pre>$_\n<br></PRE>";
}

}
close F;
}

print "<h3>", $hits ? $hits : "Geen", " bestanden gevonden</H3>";

------------------------------------------------------------------------
It still prints everything between unless [$hdrprinted ] and
$hdrprinted every hitt, does something be declared???

Thanks for the last answer you did give.
I'm verry glad you posted it.

Kind regards
Eric.
 
E

Eric Strunk

Eric Strunk said:
while (<F>) {
my $hdrprinted;
if ( /$zoek/i ) {
$hits++;
unless ($hdrprinted) {
# print the header here
$hdrprinted++;
}
print "<pre>$_\n<br></PRE>\n";
}
}

hth-

It didn't work out still have all the headers i had before, put all
the code down here again.

#!/usr/bin/perl

use strict;
use warnings;
use CGI;
use CGI::Carp ("fatalsToBrowser");
my $q = CGI->new;
my $zoek = $q->param("zoek");
chdir "/xxx/xxx.xxx.xx/xxxxx";
my @data_files = glob "*.*";

print CGI::header();
print CGI::start_html("genealogische zoekmachine");

print <<EOT;
<P><UL><BR><FONT SIZE=+1><B><I>Legenda:</I></B></FONT><P>
1 = Recordnummer<BR>
2 = Geslacht<BR>
3 = Naam en voornamen<BR>
4 = Geboorteplaats<BR>
5 = Geboortedatum<BR>
6 = Overlijdensdatum<BR>
7 = Recordnummer vader<BR>
8 = Recordnummer moeder<BR></UL><P><HR WIDTH=33% ALIGN=LEFT>
EOT


my $hits = 0;
foreach my $file ( @data_files ) {
if ( !open F, "<$file" ) {
warn "Could not open $file ($!)\n";
next;
}
my $found = 0;
while (<F>) {
my $hdrprinted;
if ( /$zoek/i ) {
$hits++;
unless ($hdrprinted) {
print "<pre> test </pre>\n";

print"<pre><b>Bestandsnaam</b><br>\n<i>$file</i></PRE><br>\n";
print "<pre> 1 </pre>" ; \
$hdrprinted++;
}
print "<pre>$_\n<br></PRE>";
}

}
close F;
}

print "<h3>", $hits ? $hits : "Geen", " bestanden gevonden</H3>";

------------------------------------------------------------------------
It still prints everything between unless [$hdrprinted ] and
$hdrprinted every hitt, does something be declared???

Thanks for the last answer you did give.
I'm verry glad you posted it.

Kind regards
Eric.

The solving answer came throug E-mail by last sender,
Thanks again.

Kind regards.
Eric.
 
M

Michael Budash

Eric Strunk said:
Eric Strunk said:
How do i get it to print it once for a file, but only if found
something in the file.

while (<F>) {
my $hdrprinted;
if ( /$zoek/i ) {
$hits++;
unless ($hdrprinted) {
# print the header here
$hdrprinted++;
}
print "<pre>$_\n<br></PRE>\n";
}
}

hth-

It didn't work out still have all the headers i had before, put all
the code down here again.

#!/usr/bin/perl

use strict;
use warnings;
use CGI;
use CGI::Carp ("fatalsToBrowser");
my $q = CGI->new;
my $zoek = $q->param("zoek");
chdir "/xxx/xxx.xxx.xx/xxxxx";
my @data_files = glob "*.*";

print CGI::header();
print CGI::start_html("genealogische zoekmachine");

print <<EOT;
<P><UL><BR><FONT SIZE=+1><B><I>Legenda:</I></B></FONT><P>
1 = Recordnummer<BR>
2 = Geslacht<BR>
3 = Naam en voornamen<BR>
4 = Geboorteplaats<BR>
5 = Geboortedatum<BR>
6 = Overlijdensdatum<BR>
7 = Recordnummer vader<BR>
8 = Recordnummer moeder<BR></UL><P><HR WIDTH=33% ALIGN=LEFT>
EOT


my $hits = 0;
foreach my $file ( @data_files ) {
if ( !open F, "<$file" ) {
warn "Could not open $file ($!)\n";
next;
}
my $found = 0;
while (<F>) {
my $hdrprinted;
if ( /$zoek/i ) {
$hits++;
unless ($hdrprinted) {
print "<pre> test </pre>\n";

print"<pre><b>Bestandsnaam</b><br>\n<i>$file</i></PRE><br>\n";
print "<pre> 1 </pre>" ; \
$hdrprinted++;
}
print "<pre>$_\n<br></PRE>";
}

}
close F;
}

print "<h3>", $hits ? $hits : "Geen", " bestanden gevonden</H3>";

------------------------------------------------------------------------
It still prints everything between unless [$hdrprinted ] and
$hdrprinted every hitt, does something be declared???

Thanks for the last answer you did give.
I'm verry glad you posted it.

Kind regards
Eric.

The solving answer came throug E-mail by last sender,
Thanks again.

Kind regards.
Eric.

which was, fyi:

change:

while (<F>) {
my $hdrprinted;

to:

my $hdrprinted;
while (<F>) {
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Need help with this script 4
Help please 8
Issue with textbox script? 0
Help with code 0
Help with my responsive home page 2
Please help with the code 0
Can't solve problems! please Help 0
Help needed with code 5

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top