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

Re: mauve::reftype()

Thread Previous | Thread Next
Zsbán Ambrus
August 30, 2010 08:13
Re: mauve::reftype()
Message ID:
On Mon, Aug 30, 2010 at 5:04 PM, demerphq <> wrote:
> On 30 August 2010 17:01, demerphq <> wrote:
>> On 30 August 2010 16:46, Zsbán Ambrus <> wrote:
>>> 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
>>> value?
>> You should get a string. Its basically a special form of SCALAR.
> And one does indeed get the string form of the pattern, if one dereferences.
> Essentially a REGEXP is a special case of a blessed string.
> basically "$qr" and $$qr are the same thing.

I don't think so:

$ ./perl -we $'$x = qr/foo/; $y = "$x"; $$z= $y; warn mauve::reftype($z);'
SCALAR at -e line 1.
$ ./perl -we $'$x = qr/foo/; $y = ${$x}; $$z= $y; warn mauve::reftype($z);'
REGEXP at -e line 1.

On Mon, Aug 30, 2010 at 5:01 PM, demerphq <> wrote:
> Yes, but it [a ref to glob] still needs to be dereferenced with a * as I recall.
> (havent verified).

No.  It can be referenced with $ fine.

$ ./perl -we $'$x = \*_y; warn $$x'
*main::_y at -e line 1.

Let me try a third equivalent definition of what I consider a scalar
ref.  If you want to use a reference as a hash key, you can't use the
string value because the reftype in the string can suddenly change
from SCALAR to REF (or the other way) while the reference remains the
same (the address doesn't change, it never gets freed, its class
doesn't change if it was blessed).  The type can, however, never
change from SCALAR to ARRAY.

$ ./perl -we '$x = bless \$y; warn "$x"; $y = *_z; warn "$x";'
main=SCALAR(0x206b760) at -e line 1.
main=GLOB(0x206b760) at -e line 1.
$ # ^^^ same address


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