>>>>> "BM" == Brandon McCaig <bamcc...@gmail.com> writes:
BM> On Tue, May 31, 2011 at 4:34 PM, Uri Guttman <u...@stemsystems.com> wrote: >> just to show another way that is usually faster for prepending a string: >> >> substr( $_, 0, 0, "$directory/" ) for @dirfiles[ 1 .. $#dirfiles ]; >> >> that is called 4 arg substr and it is way underused in perl. this >> benchmark shows the significant speedup of about 2x: BM> Thanks, Uri. :) I never would have thought substr would support such a BM> feature. In fact, I just read the perldoc and it's quite impressive BM> how it can work as an lvalue too. That's what I love about Perl. :) here's the catch. lvalue substr is older but actually very slow due to how it is implemented. 4 arg substr is much faster and does the same thing so use that and avoid lvalue. what lvalue does is mark a section of a string which you can assign into. 4 arg can do the same thing by marking the same string part and instead of an assignment it just takes the inserted string as an arg. so you see lvalue has to create something which can then be used by the assignment op which is somewhat complicated. 4 arg can just take the string and insert it where the substr tells it to. there are some obscure useful cases for lvalue substr but for all normal cases of inserting a string (and optionally replacing a part) use 4 arg substr. uri -- Uri Guttman ------ u...@stemsystems.com -------- http://www.sysarch.com -- ----- Perl Code Review , Architecture, Development, Training, Support ------ --------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com --------- -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/