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: Error help, please - comp.unix.solarishi, i need urgent help, in my messages i have ... Dev, might be able to run the script debuger on this to help me ... contents are invalid) etc - help please ... Need help ... Error handling in korn shell scripting - comp.unix.programmer ...>yes I know you need to test first, but its good to be prepared. Be prepared ... Ouch Please help script error - comp.databases.filemaker ... Korn shell script returns read ... Converting m file to pcode error... - comp.soft-sys.matlab ...Ouch Please help script error - comp.databases.filemaker ... Please help....I have a GUI m ... Hi all, I'm working on a project and I need to convert .mat files into Scilab ... script for telnet on port 25 - comp.lang.awkI need to do this >> for multiple mail servers with for loop in the shell script. >> Please Help!!! >> Regards > >You can do this in awk to (after all, it's awk's group). Environment variables in an awk script - comp.lang.awk... script variable to awk - The UNIX and Linux Forums Hi, I have a shell script with an ambedded awk script. i need to pass a script variable to the awk script. Please help. Creating a script to open single/multiple addresses in google maps ...could you please help with the script. Only last address is displayed in google maps... ... I think you need to set your variable to include itself again which ... Tcl code encryption best practice -- Please help - comp.lang.tcl ...Hi, I have a tcl script that I need to ship to my customer encrypted as it's some ... synthesis practice ... values to file in VHDL? - comp.arch.fpga please help me ... Help using Image Magick: "convert -recolor" - comp.graphics.misc ...Ouch Please help script error - comp.databases.filemaker ..... www.servers ... perl can ... infosystems.www.servers ... ... comp.soft-sys.matlab ..... sys.matlab Need help ... Trouble with NLMIXED - comp.soft-sys.sasPlease forgive my lack of knowledge...I am ... to help me solve the problem, but please let me know if more information is required! I am using a formula in my script to ... command line awk script summing values in column i - comp.lang.awk ...BTW, I don't think your post contributed anything to my knowledge of awk. ... need help on an awk script - comp.lang.awk command line awk script summing values in column i ... Custom Script / Plugin Needed PHP & Java Knowledge Required ...I need a Wordpress plugin that works to track the web visitor source so that a specific slide down bar appears according to where the web visitor came from...or who ... Finish Nearly Complete Application-FoxPro Knowledge Required ...We hired a freelancer on oDesk for $2,500 to complete a web application. The web application scrapes data (lots of it) and then generates reports based on that data. 7/7/2012 12:16:35 AM
|