Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

scalar(*main::{VALUE}) appears to return a string rather than a value?

by Don Coyote (Pilgrim)
on Nov 11, 2012 at 13:38 UTC ( #1003331=perlquestion: print w/ replies, xml ) Need Help??
Don Coyote has asked for the wisdom of the Perl Monks concerning the following question:

hacking on %main::, I printed out keys and values. The $=>*main::$ looked an ideal candidate to test out my uninformed theories about local on. When I asked scalar($main::{$}) though the string of the value of the key was returned rather than a value as I was expecting.

scalar($main::{$}), or scalar($main::{q<$>}) from cli, returned the string *main::$ which is the hash value for *main::$ and not a numeric value as I was expecting.

Is this something to do with the implicit recursiveness of the main hash?

Update: oh its scalar() behaviour. returns the scalar if it is a scalar else returns the number of items if its a list being brought into scalar context. Of course!

Comment on scalar(*main::{VALUE}) appears to return a string rather than a value?
Replies are listed 'Best First'.
Re: scalar(*main::{VALUE}) appears to return a string rather than a value?
by Anonymous Monk on Nov 11, 2012 at 14:05 UTC

    Is this something to do with the implicit recursiveness of the main hash?

    No, but "stash" is a "stash" :)( I assume a)

    What you got is a typeglob, they store everything $ is

    $ perl -l - print for $$, ${ '::$' }, ${ $main::{ '$' } }; &{ $main::{ '$' } }; __END__ 2840 2840 2840 Undefined subroutine &main::$ called at - line 2.

    $ perl -e " use Data::Dump::Streamer; Dump $main::{ q{$} }; " $VAR1 = *{'::$'}; *{'::$'} = \4032; $ perl -e " use Data::Dump; dd $main::{ q{$} }; " do { my $a = *main::$; $a = \2104; $a; }

        ok I think I see this now

        print qq{caret is the special variable symbol for $^}.$/; ALTERPIDSYM: { local $main::{'$'} = q{^}; my $grapplehook = 'tri'; print ${'::$'}; print q{?},$grapplehook; }; print ${ $main::{'$'} }; exit 0;

        {local ${$main::{q<$>}=q<Coyote>}=q<heheh>;$^=${main::{q<$>}},$$;print($^);}

        Thanks for the references Anon :)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1003331]
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (8)
As of 2015-07-28 07:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (252 votes), past polls