Please help with a script, knoledge needed!

  • Follow


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.
0
Reply Eric 6/24/2003 12:41:40 AM

In article <nf7ffv47h4efaiu3ps50u80s5vsdv62nih@4ax.com>,
 Eric Strunk <estrunk @ home.nl> wrote:

> 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-

-- 
Michael Budash
0
Reply Michael 6/24/2003 12:49:56 AM


On Tue, 24 Jun 2003 00:49:56 GMT, Michael Budash <mbudash@sonic.net>
wrote:

>In article <nf7ffv47h4efaiu3ps50u80s5vsdv62nih@4ax.com>,
> Eric Strunk <estrunk @ home.nl> wrote:
>
>> Hello all,
>> 

Cut out
----------------------------------------------------------

>
>^^^^^^^^^^^^^^^^^^^
>remove this line
>
>>         }

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

>> 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-

Great that's working the way it must work.

Many thanks for solving the problem, and thanks again.

Eric.

0
Reply Eric 6/24/2003 4:52:16 PM

On Tue, 24 Jun 2003 00:49:56 GMT, Michael Budash <mbudash@sonic.net>
wrote:

>In article <nf7ffv47h4efaiu3ps50u80s5vsdv62nih@4ax.com>,
> Eric Strunk <estrunk @ home.nl> wrote:
>
>> 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-
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.

0
Reply Eric 6/24/2003 7:57:04 PM

In article <jrahfv0ehjdv9o8ff1l2p4bjaaibidk5nv@4ax.com>,
 Eric Strunk <estrunk @ home.nl> wrote:

<snip>

> 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-
-- 
Michael Budash
0
Reply Michael 6/24/2003 8:24:55 PM

On Tue, 24 Jun 2003 20:24:55 GMT, Michael Budash <mbudash@sonic.net>
wrote:

<snip>

>> 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.
0
Reply Eric 6/24/2003 9:26:39 PM

"Eric Strunk" <estrunk @ home.nl> schreef in bericht
news:kmfhfv8bvtd5sg33thua4rm8pqvop8h09a@4ax.com...
> On Tue, 24 Jun 2003 20:24:55 GMT, Michael Budash <mbudash@sonic.net>
> wrote:
>
> <snip>
>
> >> 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.


0
Reply Eric 6/26/2003 5:45:11 PM

In article <bdfbeq$orj$1@news4.tilbu1.nb.home.nl>,
 "Eric Strunk" <estrunk @ home.nl> wrote:

> "Eric Strunk" <estrunk @ home.nl> schreef in bericht
> news:kmfhfv8bvtd5sg33thua4rm8pqvop8h09a@4ax.com...
> > On Tue, 24 Jun 2003 20:24:55 GMT, Michael Budash <mbudash@sonic.net>
> > wrote:
> >
> > <snip>
> >
> > >> 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>) {


-- 
Michael Budash
0
Reply Michael 6/26/2003 5:54:00 PM

7 Replies
32 Views

(page loaded in 0.111 seconds)

Similiar Articles:













7/7/2012 12:16:35 AM


Reply: