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
In reply to Re: Question on SV internals
by BrowserUk
in thread Question on SV internals
by John M. Dlugosz
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |