http://www.perlmonks.org?node_id=400103

gaal has asked for the wisdom of the Perl Monks concerning the following question:

When is the return value of the ref builtin "REF"? What does this say about the argument, and why would I care? Is it possible to concoct a variable with this ref value from pure Perl?

What the ref builtin returns "depends on the type of thing the reference is a reference to", says perlfunc. But according to all the discussions I've seen, a reference in Perl is a scalar. I can print ref \"something" to support this.

Presumably, when using the API, I can create an RV and that would return REF. The following is from sv.c:

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.] */

(Spookiness about "backwards compatibility" deliberately left in.)

So where is this REF thing useful? Where do you even get one? How come my pure perl reference above was not an RV (if it were, I wouldn't get SCALAR as a result of the builtin)?