PERL is really good for writing the kind of string/file parsing programs that I usually need to do.

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?


In reply to Hints to PERL by PoorLuzer

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.