And the clouds parted, and Adamiec, Larry said... > Given the following lines: > > $MESSAGE .= "<P>Application Fee: <B>" . $price . " Dollars U.S.</B>"; > > $MESSAGE .= "<P>Application Fee: <B>$price Dollars U.S.</B>"; > > > Is there a performance issue (or any other issue) for using either of > the above lines? Does it make any difference which is used? > > Suppose it changed to the following: > > $MESSAGE .= "<P>Application Fee: <B>" . $query-param('price') . " > Dollars U.S.</B>"; > > or > > $MESSAGE .= "<P>Application Fee: <B>$query-param('price') Dollars > U.S.</B>"; > > I have used the first two lines without any noticeable difference, but I > didn't use any sort of debugging/timer tools either. I am debating with > myself about which line from the second set I should use. In all > instances the correct value of "price" was inserted into the variable > $MESSAGE. > > Larry
Hi Larry- The first thing I would suggest is to check out the Benchmark::Timer module off of CPAN. You can time just about any section of your code and print a report at the end to help you see where your optimization time would best be spent. Let me know if you would like some example code to see how to use it. Using this and a simple (contrived) script, I ran some tests and it looks like the inline versions ("foo $var bar") might be slightly slower than their "append" counterparts ("foo " . $var . " bar"), although the timings sometimes drifted in the other direction based on how many trials I ran (more trials == inline gets faster), a result I suspect can be attributed to caching at some level. Basically, there wasn't enough deviation to be able to point to either one as significantly slower than the other. One of the heavier technical perldocs may have the answer, but I did a quick scan through 'perldoc perltoc' and nothing jumped off the page at me. YMMV. So I would suggest running *your*own* tests on some test data of your own to get a better idea what will work best in *your* environment. Also keep in mind that unless your script does several thousand of these assignments or your benchmarking shows that the majority of your script's runtime is spent in these assignments, you probably won't see much of a difference in performance by figuring out which one saves you 3 ms over the other. :) I'm all for optimizing code just for the sake of good programming, but if you're trying to ameliorate a performance problem, you want to look for the part of your script where it's spending the most time. HTH- Brian PS - $query-param('price') should be $query-param{'price'} - curly brackets for hashes, parens for subroutines. /~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\ | Brian Gerard Dawn is nature's way of telling you to | | First initial + 'lists' go to bed. And to just stay there until | | at technobrat dot com the evil yellow disk is gone again. | \______________________________________________________________________/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>