develooper Front page | perl.perl5.porters | Postings from August 2010

Re: mauve::reftype()

Thread Previous | Thread Next
Zsbán Ambrus
August 30, 2010 07:46
Re: mauve::reftype()
Message ID:
On Mon, Aug 30, 2010 at 2:16 PM, Ben Morrow <> wrote:
> Quoth
>> LVALUE (C<< (&{sub { *x = \$_[0] }}(substr("",0)), \$x) >>)
> It doesn't need to be that complicated. \substr("", 0) will do just
> fine. I don't think it's worth trying to include a '\$x' where it adds
> that much complication.

True, that should be simplified, my error.

>> GLOB (C<< \($x = *y) >>)
> I presume you included $x in the example because you think this is
> 'really' a SCALAR ref? I disagree. Globrefs are different from scalar
> refs in important ways; apart from anything else, they've got their own
> deref operator.

The point here is this.  Any of SCALAR, REF, GLOB, VSTRING, LVALUE can
be returned by reftype(\$y), depending on the current contents of $y,
but the other types like ARRAY can't.  Phrasing in another way, if you
have a reference $x and reftype($x) once returns SCALAR or GLOB, it
could later return the other one even if you don't assign to $x
meanwhile (eg. you don't execute $x = []) just because the value of
some other scalar changes.  As for a GLOB, I assume you understand
that's returned when $x is a reference to a scalar that's set to a
glob, not when $x is itself a glob, eg. for $x = \*y, but not for $x =
*y.  As I said earlier,

On Mon, Aug 30, 2010 at 11:07 AM, Zsbán Ambrus <> wrote:
> could we finally have a reftype that does away with the
> REF/GLOB/LVALUE/whatever madness and just returns SCALAR for any
> scalar, independent of what value it has?  The precise invariant I'd
> like is that refaddr($x) remains constant when you assign to $x but
> not to $x.

>> REGEX (C<< qr// >>)
> A REGEX, OTOH, could reasonably be considered a SCALAR ref. It's derefed
> with $, the result fits in a scalar variable, &c.

Hmm, true.  In this case, maybe the entry should say

REGEX (C<< \($x = ${qr//}) >>)

Though I don't really understand how that works.  What do you even get
if you dereference a regexp with ${...}, and how can you use that


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About