Now if I perform another numeric operation on that value, does it remember that it was 20 and not convert it again?

Short answer: Yes, until you next use it in a string context.

Ie.

@a = 1 .. 1e6;; print total_size \@a;; 32000176 "$_" for @a;; Useless use of string in void context at (eval 11) print total_size \@a;; 72000176 @a = 1 .. 1e6;; print total_size \@a;; 32000176 ''.$_ for @a;; Useless use of concatenation (.) or string in void context at (eval 15 +) print total_size \@a;; 72000176

What the above shows is that apparently innocent and even useless references to numeric scalars in string contexts can cause a quite dramatic explosion in memory usage.

Most of the time, individual scalars and small aggregates, this is inconsequential, but if you are dealing with large aggregates close to the limits of your memory, it can be worth your while to take care to prevent such conversions:

@a = 1 .. 1e6;; print total_size \@a;; 32000176 do{ my $n = $_; "$n" } for @a;; Useless use of string in void context at (eval 23) line 1, <STDIN> lin +e 15. print total_size \@a;; 32000176

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re: Question on SV internals by BrowserUk
in thread Question on SV internals by John M. Dlugosz

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.