You ask,
After such an interpolation happens - is the object the reference is/was pointing to destroyed if this was the last reference.
In your particular code, the answer would be now as $ref variable that also stores the reference is still 'effective' or within the scope. However, if you had something like this:
my $ref2;
{ # Block A
my @aha = (1,2,3,4,5);
my $ref = \@aha;
$ref2="$ref";
}
print "@$ref\n";
print ref($ref), " $ref\n";
print ref($ref2)," $ref2\n";
I believe, the answer would be 'yes' when you are at a point in your code outside of 'Block A'.
UPDATE: Regarding your second question (B), you could try using
Devel::Pointer to fiddle around with your 'stringified' references and bring them back to 'life'. Try this code, for example (warning: I haven't tested this...):
use Devel::Pointer;
my @aha = (1,2,3,4,5);
my $ref = \@aha;
my $ref2 = "$ref";
my ($addr) = ($ref2 =~ m/\(\0\x(\d+)\)/);
$real_ref = deref($addr);
# $real_ref must now point to the @aha array..
UPDATE 1: In addition to
Devel::Pointer, there's this
PeekPoke module that you might also find interesting. Basically, it allows you to peek a value stored at a given address. Of course, due to the nature of Perl variables (arrays specifically), I wouldn't advice this method for actually accessing individual array's elements. Unlike in C where each array's element could be easily accessed via a pointer (or address peek), Perl arrays is a bit more involved structure, and the address you get with
\@array isn't pointing to the first array element but rather the beginning of the Perl structure representing the array. ..
_____________________
$"=q;grep;;$,=q"grep";for(`find . -name ".saves*~"`){s;$/;;;/(.*-(\d+)
+-.*)$/;
$_=["ps -e -o pid | "," $2 | "," -v "," "];`@$_`?{print"+ $1"}:{print"
+- $1"}&&`rm $1`;
print$\;}
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.