* "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. > >> $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." > 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. -- rjbs
pgp00000.pgp
Description: PGP signature