does it push the value, or just a pointer?
When you're passing around objects, really you're passing around special references. So even if you have two scalars pointing to one struct, it's that same struct you're modifying, regardless of how it's named.
It might be easier to illustrate with an example:
use Class::Struct;
use strict;
struct Test => [ xyz => '$' ];
our $T = new Test(xyz => 123);
print "\$T->xyz starts as: ", $T->xyz, "\n";
no strict 'refs';
my $symbolic = "T";
${$symbolic}->xyz(456);
print "\$T->xyz is now: ", $T->xyz, "\n";
my %A
$A{t} = $T;
$A{t}->xyz(789);
print "\$T->xyz is now: ", $T->xyz, "\n";
__END__
$T->xyz starts as: 123
$T->xyz is now: 456
$T->xyz is now: 789
To get "full" copy effects, you need to make a copy of each of the fields:
my $a = new Test ( xyz => 123 ); # original
my $b = new Test ( xyz => $a->xyz ); # copy of a
$b->xyz(456);
printf "a=%d b=%d\n", $a->xyz, $b->xyz; # a=123 b=456
I don't know of an easy way to "deep copy" struct objects, though the Clone module (or Storable's 'dclone' function) may help.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.