>>>>> "Prabu" == Prabu Ayyappan <[EMAIL PROTECTED]> writes:

Prabu> Below are some of the way to optimize the perl code. You can add more
Prabu> to this if you have something more.

How about subtract from things that are wrong?

Prabu> 2) Static string Handling
Prabu> use single quotes rather than doubles. Double quotes force Perl to look 
for a potential interpolation of information, which adds to the overhead of 
printing out the string.
Prabu> Print I am a static string I dont want to get interpolated;
Prabu> If we want to interpolate then do it as like this
Prabu> Print I am a static string , \n , I dont want to get interpolated;

This is completely bogus.  The code:

     print 'hello'

and

     print "hello"

compiles to precisely the same internal tree structure.  There is absolutely
*no* difference of these two at runtime.

Prabu> 3) Many if statements can be incredibly time consuming 
Prabu> if ($a > 0)
Prabu> {  $c = $a; }
Prabu> elsif ($b > 0)
Prabu> {  $c = $b; }
Prabu> else
Prabu> {   $c = $d; }
Prabu> This can be time consuming, waste of space. 
Prabu> Can be replaced with  $c = $a || $b || $d;
Prabu> If $a is a true value, Perl doesn't even look at the other variables. If 
$a is false, then Perl checks the value of $b and so on until it gets to the 
last value, which is always used, whether it's true or not.

This is also bogus.  You're not comparing comparable operations, for one.
if $a < 0, then $c will get $a in your rewritten || case.

Even if you rewrote it to "!=" for the two comparisons, the speed of the
operations would be roughly equal, as clearly the comparison of $b to 0 won't
happen because of the elsif.  This completely undermines your argument, once
you've fixed your code.

Prabu>  Best Regards,
Prabu> Prabu.M.A

I'd hate to think of what the "M.A." stands for here.

In any case, since you were wrong on two out of three of your advice items to
the mailing list, the mailing list would do *better* *without* your
contribution *for now*.  Please take a rest, and learn some more, before
coming off like you know Perl.  I've earned that right.  You haven't yet. :)

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[EMAIL PROTECTED]> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to