Well, let me give a few suggestions which do not bear directly upon your problem (the exact nature of which remains fuzzy to me).

First, after #/usr/bin/perl append -wT. The -w flag will give you helpful warnings, and the -T flag will help keep people from doing bad things with your script.

Second, place the following line near the beginning of your program, right around line 2:

use strict;

Then go around and correct all the errors which pop up by using the my keyword. As this program stands, there's practically no reason to use subroutines at all. Since, from what I gathered in the CB, you're up against a very near deadline, maybe you could postpone this... but do get around to it ASAP. It's important. Besides, it will teach you a lot.

Third, right around line three, insert the following line:

use CGI qw/:standard/;

Shortly thereafter, insert the following line:

my %FORM = map {$_ => param($_)} param();

Now you may eliminate the parse_form subroutine, since the form has been parsed, and the parameters stored in %FORM. The moral of this story is, use the CGI module. It's better and safer than doing this sort of thing yourself (as many monks will tell you in much stronger terms).

The CGI module also allows you, in your return_html subroutine, to tidy things up considerably. Instead of saying:

print "Content-type: text/html\n\n"; print "<html>\n <head>\n <title>Results of Search</title>\n </head>\n +"; print "<body>\n <center>\n <h1>Results of Search in $title</h1>\n</ce +nter>\n";

You can now say:

print header, start_html('Results of Search'), h1({-align=>'center'},"Results of Search in $title");
Next, @files contains but a single string, which means it's not much of an array. And then you only use it once, in a for loop. Now if you only own one dog, and you leave it with your friend, you can tell him, "make sure you feed each of my dogs". But you probably would rather say, "make sure you feed my dog". Hence, change the line:

@files = ('*.dtl');

to:

$file = '*.dtl';

and then delete the line:

foreach $file (@files) {</code>

as well as the last } in the get_files subroutine.

Oh, yeah... and what's with that line:

@$string3 = ($LINES[15]);

? I'm guessing that's a typo, and that the @ doesn't belong there.

There's a bunch of other stuff, but I'm tired, and anyway, I don't want to be (more) pedantic. Really, as dws points out, this is a pretty good first effort. I can see why you're lost and frustrated, though. Your code is more complex than it needs to be. If you're able to simplify things, you'll see the logic behind what you're doing much more clearly.

Also, implement these suggestions one at a time, and test as you go along. I have not tested them; the code I've written is off the top of my head, and my head is sleepy. Never trust code (at least) until you see it work. :-)

Good luck.


In reply to Re: malaga's hash/array/search problem by Petruchio
in thread malaga's hash/array/search problem by malaga

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.