PoorLuzer has asked for the wisdom of the Perl Monks concerning the following question:
What I really love is the insignificant amount of time it takes me to write quick scripts and throwaway code, compared to C/C++/JAVA.
However, I want to learn how to speed things up.
For example, I would want to learn how to give hints to PERL so that it can make some decisions better - specially things related to strings.
It seems to me that perl copies a string whenever you do anything, regardless of whether you really modify the copy later or not?
Is this by design (and can I turn that away using some magic?) or am I ranting?
I really want to treat some strings as (const char *) - I am sure we always do not need everything to be a std::string with all its baggage involved (let's assume std::string to be analogous to PERL string)
Can I hint PERL to do that on some strings?
I remember reading in some article (please comment if you can place it) that you can hint PERL that you will not modify some variable and thus it removes the extra baggage that is otherwise required if you were to modify it etc?
I believe PERL variables have two internal pointers to a same PERL variable - one can store a number and another a string (array of characters) - could we always ask PERL to choose one throughout?
Could we make PERL treat some strings as (const char *) so that they do not tag around functionality required to modify them?
For example, I read somewhere (maybe the same article?) that unpack() is faster than substr() because substr() returns a lvalue, so that you can operate on it as well.
For example, if you wanted to replace the first two characters of a string with 'ef', you could write:
substr(string, 0, 2) = 'ef'; # string now begins with 'ef'
Hence, unless you are using this special feature of substr(), you are better off using substr?
Did I just rant all the way through?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Hints to PERL
by roboticus (Chancellor) on May 18, 2009 at 23:18 UTC | |
|
Re: Hints to Perl
by jettero (Monsignor) on May 18, 2009 at 22:14 UTC | |
|
Re: Hints to PERL
by Anonymous Monk on May 19, 2009 at 08:14 UTC | |
by jvector (Friar) on May 19, 2009 at 19:54 UTC | |
by Anonymous Monk on May 20, 2009 at 03:55 UTC | |
|
Re: Hints to PERL
by nikosv (Deacon) on May 19, 2009 at 09:28 UTC |