Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
One note about style:
You might find it cleaner, and I believe it is quicker, if you group your print statements or use a "heredoc".
print "abc\n"; print "def\n"; print "ghi\n"; becomes print "abc\n", "def\n", "ghi\n"; or print << EOD; abc def ghi EOD
You can do this as well with your  print MAIL section.

You have some pretty long parameter lists, you might want to consider named parameters.

Get rid of temporary variables:

use CGI qw(:cgi); my $url = $_[0]; my $q = CGI->new(); print $q->redirect( -url => $url ); # becomes my $q = CGI->new(); print $q->redirect( -url => $_[0] );

You use a lot of post-conditionals, and I tend to as well, but you may want to re-evaluate whether some of them make the code more difficult to read than others. A test is whether the condition or the result is "more important" and use that to determine which goes first.

&get_data (\$current_date, \$remote_host, \$remote_addr, \$server_name); #... sub get_data { my ($current_date, $remote_host, $remote_addr, $server_name) = @_; #.... # get the information about who submitted the form $$remote_host = $ENV{'REMOTE_HOST'}; $$remote_addr = $ENV{'REMOTE_ADDR'}; $$server_name = $ENV{'SERVER_NAME'}; }
Why bother passing in the references? Just return the scalar values:
($current_date, $remote_host, $remote_addr, $server_name) = get_data(); sub get_data { #... # get the current date ($day, $month, $year) = (localtime)[3,4,5]; $year += 1900; return ( "$months[$month] $day, $year", $ENV{'REMOTE_HOST'}, $ENV{'REMOTE_ADDR'}, $ENV{'SERVER_NAME'}; }

And just to restate, use CGI;

Hope this is useful.


In reply to Re: Some suggestions on coding style - a chance to critique by Sifmole
in thread Some suggestions on coding style - a chance to critique by emilford

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2024-04-19 21:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found