Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: malaga's hash/array/search problem

by Petruchio (Vicar)
on Jan 18, 2001 at 13:11 UTC ( [id://52734]=note: print w/replies, xml ) Need Help??


in reply to malaga's hash/array/search problem

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://52734]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2024-04-24 01:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found