I use Perl for the web. A lot. So I am trying to do this neat little thing with the grep function. That is the key to my little search engine for looking up names. The only trouble is when I try to use it, the darn thing doesn't work. I thought it was with the file that the contains the names. But it isn't that. I use HTML::Template heavily here, so could someone check over my code and see if it is correct, or maybe where I am going wrong?
#!/usr/bin/perl #Start the modules use strict; use CGI; #Create a new CGI object my $Page = new CGI; #The secret ingredient! use lib "../lib"; use HTML::Template; #Save that shit my $Shit = $Page->param('Info'); my $Le_File = $Page->param('file'); #If they used more than one word my $Wrong_Text = <<'TEXT'; You used a space in your query, which you should have not done. Instead, just use only one word. Please try your query again. TEXT #If they typed a symbol at the front of the word my $Wrong_Symbol = <<'WRONG'; Don\t type a symbol at the front of the word. Instead, just type the word in and hope for the best. Or, use the symbol \^ at the start of the word for matching names beginning with that word. Conversely, use \$ at the end of the word to get names ending in that word. Plus, this stuff is case sensitive. WRONG #If there is no file unless(open 'FILE', "../$Le_File") { print $Page->header(); print <<HTMLSTUFF; <html> <head> <title> No file </title> <body> <p>Make sure the file $Le_File is there</p> <p>Now exiting program</p> </body> </html> HTMLSTUFF exit; } #Start a new template my $Template = HTML::Template -> new(filename => '../Template/Search_E +ngine.tmpl'); #Check the variable to see if it has spaces in it if ($Shit =~ m/ /g) { $Template->param(Bad_Stuff => "$Wrong_Text", option => 'value' +); print $Template->output(); exit; } #Weed out other shit elsif ($Shit =~ m/^(\+|\-|\!|\#|\\)/g) { $Template->param(Bad_Stuff => "$Wrong_Symbol", option => 'valu +e'); print $Template->output(); exit; } #Read the whole thing into an array my @Lines = <FILE>; close(FILE); #Use grep to find the goods my @Names = grep(m/$Shit/, @Lines); ############The whole thing #Print out the word Results $Template->param(Results => "<p>Here\'s the results for $Shit<\/p> +"); #Use the looping schtick in HTML::Template to print out of the informa +tion in the array $Template->param(LE_LOOPY => [Le_Names => "@Names"]); ##########End it all #And finally print $Template->output();
Thanks for any help.

Edit by dws for a more appropriate title


In reply to Problem using HTML::Template. by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.