Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

rookie needs help

Status
Not open for further replies.

jwset

Technical User
Aug 18, 2002
9
US
I have a text file that I am trying to do a search on that will search for the input from the html page then if found return that line of information to a html page if not found will return a html page that says member not found

I have the code but when i run it retruns the following;
Search Results

END_HTML my = grep(/^jwset|/i, ); if () { foreach () { chomp; my = split /|/; print '', join(',', ), " "; } } else { print "
No results found.

&quot;;} print < Search Brought to you by Guild Masters

it is not doing the search for the name entered. can anyone help me with what I have wrong with the code.

here is the code;
#!/usr/bin/perl
use CGI qw:)standard);
my $member_data = 'members.dat';
my $searchstr = param('username'); #name from html page
open(INF , &quot;$member_data&quot;) ||die(&quot;Cannot Open Files&quot;);
print header;
print <<END_HTML;
<HTML>
<BODY BGCOLOR=&quot;#FFFFFF&quot; TEXT=&quot;#000000&quot; LINK=&quot;#0000FF&quot; VLINK=&quot;#800040&quot; ALINK=&quot;#800040&quot;>
<TITLE>Search Results</TITLE>
<CENTER><BR><FONT SIZE=&quot;5&quot; COLOR=&quot;#000000&quot; FACE=&quot;ARIAL,TIMES NEW ROMAN&quot;>Search Results</FONT></CENTER><BR>
END_HTML
my @results = grep(/^$searchstr\|/i, <INF>);

if (@results)
{
foreach (@results)
{ chomp;
my @record = split /\|/;
print '<b>', join(',', @record), &quot;</b>\n&quot;;
}
}
else { print &quot;<p>No results found.</p>\n&quot;;}
print <<END_HTML;
<HR width=&quot;80%&quot; noshade> <FONT SIZE=&quot;3&quot; COLOR=&quot;#000000&quot;
FACE=&quot;ARIAL,TIMES NEW ROMAN&quot;>Search Brought to you by Guild Masters</A></FONT></CENTER> </CENTER>
</A>
</BODY>
</HTML>
END_HTML

thank you for any help that I can get. been working on this for 2 weeks now to try and get it to work.
 
You could try changing
print <<END_HTML;
to
print <<END_HTML
Both should work, but since the first one doesn't seem to work for you, you could try and change it. //Daniel
 
I tried by changing it like you showed, but still did not help. Doing the exact same thing.

Anyone got another idea whats wrong maybe.
 
You probably have whitespace after the first END_HTML. Either that or it isn't left justified. It must start at the very left edge, no leading whitespace, and cannot contain trailing whitespace.

jaa
 
On a side note...
Instead of doing the [tt]split[/tt] and [tt]join[/tt] on each record, it would be more efficient (and probably faster) to do
Code:
foreach (@results)
{
    chomp;
    s/\|/,/g;
    print &quot;<b>$_</b>\n&quot;;
}

jaa
 
That was the problem, I had white space after the code for the END_HTML. I chacked all lines and had on a couple of them. Thank you all for your help. It was driving me crazy.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top