For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > March 2006 > confusing question about GLOB









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author confusing question about GLOB
Jeff Pang

2006-03-28, 3:58 am

hello,list,

See these commands pls:

[coremail@msfw coremail]$ perl -le 'our %test = (type => "software"); print $::{test}'
*main::test
[coremail@msfw coremail]$ perl -le 'our %test = (type => "software"); print ${*main::test{HASH}}{type}'
software
[coremail@msfw coremail]$ perl -le 'our %test = (type => "software"); print ${$::{test}{HASH}}{type}'
[ no output ]

The first command prove that " $::{test} == *main::test ";
The second command access the GLOB *main::test and get the value 'software' in hash %test.

My question is:
why I get nothing via accessing the $::{test} which is equl to *main::test in the third command?Thanks.

--
Jeff Pang
NetEase AntiSpam Team
http://corp.netease.com
John W. Krahn

2006-03-28, 6:57 pm

Jeff Pang wrote:
> hello,list,


Hello,

> See these commands pls:
>
> [coremail@msfw coremail]$ perl -le 'our %test = (type => "software"); print $::{test}'
> *main::test


You are printing the value for the key 'test' in the hash %:: (the symbol
table; see the "Symbol Tables" section of perlmod.)

> [coremail@msfw coremail]$ perl -le 'our %test = (type => "software"); print ${*main::test{HASH}}{type}'
> software


*main::test{HASH} returns a hash reference to the 'test' symbol table entry
(see part 7 of the "Making References" section of perlref.)

> [coremail@msfw coremail]$ perl -le 'our %test = (type => "software"); print ${$::{test}{HASH}}{type}'
> [ no output ]


You are trying to print $::{test}->{HASH}->{type} but $::{test} does not
contain a hash reference.

> The first command prove that " $::{test} == *main::test ";
> The second command access the GLOB *main::test and get the value 'software' in hash %test.
>
> My question is:
> why I get nothing via accessing the $::{test} which is equl to *main::test in the third command?Thanks.


%:: is the symbol table in the package 'main', *main::test is the type glob
'test' in the package 'main'. You are dealing with two different variables.


John
--
use Perl;
program
fulfillment
Jeff Pang

2006-03-28, 6:57 pm


>
>You are trying to print $::{test}->{HASH}->{type} but $::{test} does not
>contain a hash reference.
>


Thanks John.Then why can this work?

$ perl -le 'our %test = (type => "software");print ${*{$::{test}}{HASH}}{type}'
software

I saw that someone other on this list had written this statement,but It's hard to understand for that.

--
Jeff Pang
NetEase AntiSpam Team
http://corp.netease.com
John W. Krahn

2006-03-28, 6:57 pm

Jeff Pang wrote:
>
> Thanks John.Then why can this work?
>
> $ perl -le 'our %test = (type => "software");print ${*{$::{test}}{HASH}}{type}'
> software
>
> I saw that someone other on this list had written this statement,but It's hard to understand for that.



$ perl -le'our %test = (type => "software");
print $::{ test };'
*main::test

$ perl -le'our %test = (type => "software");
print for *{ $main::{ test } }{ HASH },
*{ *main::test }{ HASH },
\%main::test;'
HASH(0x8187774)
HASH(0x8187774)
HASH(0x8187774)

$ perl -le'our %test = (type => "software");
print for ${ *{ $::{ test } }{ HASH } }{ type },
${ *{ *::test }{ HASH } }{ type },
${ { %test } }{ type },
${ \%test }{ type },
${ test }{ type },
$ test { type };'
software
software
software
software
software
software




John
--
use Perl;
program
fulfillment
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com