On Dec 25, 2003, at 5:02 AM, [EMAIL PROTECTED] wrote:
Here's the code which I expected to work, but doesn't. I'm expecting \$$orig to result in a new reference, but instead it's reusing the original reference that I started with.
So:
$s = "some string"; $orig = \$s; $new = \$$orig; print "orig:$orig, new:$new\n";
Results in these values:
orig:SCALAR(0x17753dc), new:SCALAR(0x17753dc)
bear with me, I am slow this morning.
if you went with "$new = $$orig" then your new holds the value that $s holds. Hence it would not be a 'reference' to that string...
Plan A: would seem to be the simple
my $bob = $$orig; #copy the substance of $orig my $new = \$bob; #take a reference to the new memory
Plan B: would be to make a function like:
#------------------------ # sub clone_me { my ($me,$item) = @_; my $ref_type = ref($item); return $item unless $ref_type; if ( $ref_type eq 'SCALAR' ) { my $new_item = $$item; return(\$new_item); }elsif ($ref_type eq 'ARRAY' ) { my $count = 0; my @array; $array[$count++] = $me->clone_me($_) foreach(@$item); return([EMAIL PROTECTED]); } # solve the case for a hash ref } # end of clone_me
ciao drieux
---
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>