perlquestion
gaal
When is the return value of the <code>ref</code> builtin "REF"? What does this say about the argument, and why would I care? Is it possible to concoct a variable with this <code>ref</code> value from pure Perl?
<readmore>
<p>What the <code>ref</code> builtin returns "depends on the type of thing the reference is a reference to", says [perldoc://perlfunc]. But according to all the discussions I've seen, a reference in Perl is a scalar. I can <code>print ref \"something"</code> to support this.
<p>Presumably, when using the API, I can create an RV and that would return REF. The following is from sv.c:
<code> switch (SvTYPE(sv)) {
/* [snip] */
case SVt_RV: /* [snip IV, PV, etc., all falling through] */
case SVt_PVBM: if (SvROK(sv))
s = "REF";
else
s = "SCALAR"; break;
case SVt_PVLV: s = SvROK(sv) ? "REF"
/* tied lvalues should appear to be
* scalars for backwards compatitbility */
: (LvTYPE(sv) == 't' || LvTYPE(sv) == 'T')
? "SCALAR" : "LVALUE"; break;
case SVt_PVAV: s = "ARRAY"; break;
case SVt_PVHV: s = "HASH"; break;
/* [snip CODE etc.] */
</code>
<p>(Spookiness about "backwards compatibility" deliberately left in.)
<p>So where is this REF thing useful? Where do you even get one? How come my pure perl reference above was <em>not</em> an RV (if it were, I wouldn't get <code>SCALAR</code> as a result of the builtin)?