Previous Thread
Next Thread
Print Thread
Rate Thread
#102017 01/17/2001 4:53 PM
Joined: Sep 2000
Posts: 138
Em8
Offline
Member
Member
Offline
Joined: Sep 2000
Posts: 138
Can I improve to this?
Code
code:

------------------

Sponsored Links
#102018 01/18/2001 11:25 AM
Joined: Aug 2000
Posts: 335
Member
Member
Offline
Joined: Aug 2000
Posts: 335
Since you're using CGI.pm objects, I think it would be cleaner to have 'use CGI()' instead of 'use CGI qw(:standard)', to avoid unnecessary importing of names into the global namespace.

If you do that, 'print header' should be 'print $q->header()'.

It's also a good idea to turn on warnings, taint and strict modes:
#!/usr/bin/perl -wT
use strict;
use re 'taint'; # suppress implicit untainting by regexes

With strict mode on, all variables have to be declared:
my $q = new CGI;

After reading about possible ambiguities in accessing object methods, I've gotten in the habit of using this style when calling an object constructor:
my $q = CGI::->new();

If I'm wrong about any of these suggestions, please jump in and correct me [Linked Image]

This message has been edited by Dave_L on January 18, 2001 at 10:31 AM

#102019 01/18/2001 12:12 PM
Joined: Aug 2000
Posts: 3,590
Moderator
Moderator
Offline
Joined: Aug 2000
Posts: 3,590
Dave_L -- right-on. Only thing is that when you release a script, you may want to drop the -w so you don't needlessly fill your error logs if a new version of Perl came out.

------------------


:: Who is Andy?

#102020 01/18/2001 6:26 PM
Joined: Feb 2000
Posts: 4,625
Member
Member
Offline
Joined: Feb 2000
Posts: 4,625
Sweet sig pic too. [Linked Image]

------------------

Modification Developer of the Ultimate Bulletin Board
Due to time limitation, I do not offer support Via. E-mail, ICQ , AIM, Private message or any media.
Regards,
MasterMind

#102021 01/18/2001 9:51 PM
Joined: Oct 2000
Posts: 24
Member
Member
Offline
Joined: Oct 2000
Posts: 24
A couple of moot points.

Get into the habit of 'use strict';
Not only will it run far cleaner, it also stands a better chance of being mod_perl compliant. You also don't have to worry about global variables being carried over with each execution.

Also, get out of the habit of using speech marks around everything.

if ($action eq "run"); is better written as if ($action eq 'run');

Using speech marks forces the scripts to interpolate the argument inside of it. In this case it's a waste of CPU.

Try and be a bit more explicit in your definitions.

if ($action eq "") is a little vague, better to use if (!$action), or better still:
unless (defined $action);

I always try and use 'unless' because it won't allow 'unless' 1 clause is met.

They are merely little things that help raise the standard of the code.

Finally, spend a little time working the code through logically on paper, or in your head before typing. You can remove most of the 'if {} elsif {} else {} ' clauses with a better logical workflow.

Sponsored Links
#102022 01/18/2001 10:10 PM
Joined: Sep 2000
Posts: 755
P.I.T.A. / Programmer
P.I.T.A. / Programmer
Offline
Joined: Sep 2000
Posts: 755
Quote
quote:
You don't need the defined.

unless $action;

is fine [Linked Image]


"Annnnnnnndd now, opening for Iron Maiden...... WYLD STALLYNS!!!" --Bill S. Preston, Esquire and Ted "Theodore " Logan
#102023 01/23/2001 2:02 AM
Joined: Jan 2001
Posts: 6
Junior Member
Junior Member
Offline
Joined: Jan 2001
Posts: 6
Quote
quote:
That is not true. If the item inside the quotes is a literal string,
as it is here, the compiled code is identical, and the execution time
is exactly the same.

Many people prefer to use " as their normal quotation marks, because
they're easier to see on the page, and use ' only when they want to
specifically inhibit interpolation of a string like '$5.00'.




This message has been edited by Dominus on January 23, 2001 at 01:06 AM

#102024 01/23/2001 2:09 AM
Joined: Jan 2001
Posts: 6
Junior Member
Junior Member
Offline
Joined: Jan 2001
Posts: 6
Code
quote:</font><HR><font face="Verdana, Arial" size="2">Originally posted by Em8:
Can I improve to this?<BLOCKQUOTE><font size="1" face="Verdana, Arial">code:



Did you notice that you are only generating one
random number here, not two? $run
and $attak will always have the same value.
If that is what you meant to do, I suggest replacing the two variables with only one.
But I suspect that what you wanted was something more like this:
Code
code:


Link Copied to Clipboard
Donate Today!
Donate via PayPal

Donate to UBBDev today to help aid in Operational, Server and Script Maintenance, and Development costs.

Please also see our parent organization VNC Web Services if you're in the need of a new UBB.threads Install or Upgrade, Site/Server Migrations, or Security and Coding Services.
Recommended Hosts
We have personally worked with and recommend the following Web Hosts:
Stable Host
bluehost
InterServer
Visit us on Facebook
Member Spotlight
isaac
isaac
California
Posts: 1,157
Joined: July 2001
Forum Statistics
Forums63
Topics37,573
Posts293,925
Members13,849
Most Online5,166
Sep 15th, 2019
Today's Statistics
Currently Online
Topics Created
Posts Made
Users Online
Birthdays
Top Posters
AllenAyres 21,079
JoshPet 10,369
LK 7,394
Lord Dexter 6,708
Gizmo 5,833
Greg Hard 4,625
Top Posters(30 Days)
Top Likes Received
isaac 82
Gizmo 20
Brett 7
WebGuy 2
Morgan 2
Top Likes Received (30 Days)
None yet
The UBB.Developers Network (UBB.Dev/Threads.Dev) is ©2000-2024 VNC Web Services

 
Powered by UBB.threads™ PHP Forum Software 8.0.0
(Preview build 20221218)