|
Joined: Sep 2000
Posts: 138
Member
|
Member
Joined: Sep 2000
Posts: 138 |
Can I improve to this? ------------------ 
|
|
|
|
Joined: Aug 2000
Posts: 335
Member
|
Member
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 This message has been edited by Dave_L on January 18, 2001 at 10:31 AM
|
|
|
|
Joined: Aug 2000
Posts: 3,590
Moderator
|
Moderator
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?
|
|
|
|
Joined: Feb 2000
Posts: 4,625
Member
|
Member
Joined: Feb 2000
Posts: 4,625 |
Sweet sig pic too. ![[Linked Image]](https://ubbdev.com/ubb/smilies/wink.gif) ------------------  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
|
|
|
|
Joined: Oct 2000
Posts: 24
Member
|
Member
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.
|
|
|
|
Joined: Sep 2000
Posts: 755
P.I.T.A. / Programmer
|
P.I.T.A. / Programmer
Joined: Sep 2000
Posts: 755 |
You don't need the defined. unless $action; is fine ![[Linked Image]](https://ubbdev.com/ubb/smilies/smile.gif)
"Annnnnnnndd now, opening for Iron Maiden...... WYLD STALLYNS!!!" --Bill S. Preston, Esquire and Ted "Theodore " Logan
|
|
|
|
Joined: Jan 2001
Posts: 6
Junior Member
|
Junior Member
Joined: Jan 2001
Posts: 6 |
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
|
|
|
|
Joined: Jan 2001
Posts: 6
Junior Member
|
Junior Member
Joined: Jan 2001
Posts: 6 |
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:
|
|
|
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.
|
|
Posts: 69
Joined: January 2001
|
|
Forums63
Topics37,575
Posts293,931
Members13,824
|
Most Online6,139 Sep 21st, 2024
|
|
Currently Online
Topics Created
Posts Made
Users Online
Birthdays
|
|
|
|