It seems to me that perl copies a string whenever you do anything, regardless of whether you really modify the copy later or not?
No, perl copies strings on assignment ($foo = $bar).
Example:
#!/usr/bin/perl --
use strict;
use warnings;
my $str = "foo";
my $copy = $str;
print "$copy $str\n";
nocopy($str);
yescopy($str);
print "$copy $str\n"; # now $str is foobar
sub nocopy { $_[0] .= 'bar'; '...' }
sub yescopy { my ($copy) = $_[0]; $copy = shift; $copy .= 'bar' }
__END__
foo foo
foo foobar
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?
You are probably thinking of constant and/or making variables readonly,
which forces you not to write code that try to modify those variables, as a result there is no unneeded copying
... PERL ...
The Perl community likes to call it Perl, or perl, but not so much PERL, even if its a fun bacronym generator.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.