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

Re: mauve::reftype()

Thread Previous | Thread Next
August 30, 2010 08:28
Re: mauve::reftype()
Message ID:
On 30 August 2010 17:13, Zsbán Ambrus <> wrote:
> 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.
> $

I dont understand what you think you are proving here. Well except
that the second example is pretty bizarre stuff...


And actually, i really dont think that $$z= ...; in your example does
what you think it does. It smells like a mistake ive seen Data::Dumper
make .

Although im not sure what you think it does. :-)

> 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.

But that wont give you access to the glob slots, only the name of the glob:

$ ./perl -le'our @foo=(1..2); my $gref=\*foo; print $$gref{ARRAY}'
Not a HASH reference at -e line 1.

If you want access to the glob you have to use glob dereferencing:

$ ./perl -le'our @foo=(1..2); my $gref=\*foo; print *$gref{ARRAY}'

> 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

Ah, i see what you are saying. Ok. And yes i agree that the
hypothetical "dereftype" would have to stay constant for this purpose.

Although well, really I guess one should use refaddr() for this purpose. :-)

perl -Mre=debug -e "/just|another|perl|hacker/"

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