Ricardo SIGNES wrote:
* "JupiterHost.Net" <[EMAIL PROTECTED]> [2004-05-13T11:35:58]

Bob Showalter wrote:

for instance:
 $newvariable = "$howdy";
should be:
 $newvariable = $howdy;

That's not an appropriate optimization. Perl objects can overload stringification.

Interesting... So when would that cause problems?


If $howdy is an object that returns "Hello!" when turned into a string,
then the first bit of code assigns "Hello!" to $newvariables.  The
second bit of code makes $newvariable a copy of $howdy.

I see...



$str = CGI::header() . "hello" . $v;

woudl become
$str = CGI::header(),"hello", $v;

That's not equivalent code at all.

I didn't think so but I read somewhere to use commas instead of concatenation with periods. I always thought the commas was a bit different but if you print $str; they are the samem in each example.


Look at the prototype for C<print>.  It takes a LIST, and those elements
are concatted together and printed.  (see "perldoc -f print")  The value
of $, is stuck between list elements, but it's usually empty.

So, C<print $foo, $bar> is mostly equivalent to C<print $foo . $bar> in
usual circumstances, but C<$foo = $bar, $baz> is wildly different from
C<$foo = $bar . $baz>;  the first sets foo to baz.  The second sets it
to bar and baz concatenated.


I'm sure I have much to learn as far as the period/comma thing go :)


When in doubt, look in perldoc. About comma, it says:

 Binary "," is the comma operator.  In scalar context it evaluates its
 left argument, throws that value away, then evaluates its right
 argument and returns that value.  This is just like C's comma operator.


What I'm really looking for is a similar thing to Perl::Tidy that I can run a script throught and have it make an "optomized" version.


You mean "optimized."

:) Now I need a spell checker :)




That would be complex but wouldn't it be cool?


I can't imagine wanting to use it; it would take time to run, and I
don't think I would trust it.  Perl is fast enough for me.  Better to
learn how to write fast-enough code to begin with, imho.


You wouldn't use it at runtime, you'd run your code through it and getr anew file with slicker code then use that in your normal use. But I agree better to learn and use the most efficient code :)



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




Reply via email to