develooper Front page | perl.perl5.porters | Postings from September 2003

Dumping a package

Thread Next
From:
Torsten Foertsch
Date:
September 17, 2003 05:20
Subject:
Dumping a package
Message ID:
200309171419.14903.torsten.foertsch@gmx.net
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

I'm developing a function to inspect packages. My first attempt was something 
like this:

sub dump_pkg {
  my $p=shift().'::';
  no strict 'refs';
  local $_;
  foreach (%{$p}) {
    print "key=$_\n";
    print Dumper( ${$p.$_}, \@{$p.$_}, \%{$p.$_} );
  }
}

now I create a symbol via:

$a::x::y=1;
@a::x::y=('hallo');
%a::x::y=(hallo=>1);

and call my function:

dump_pkg( 'a::x' );

and get

key=y
$VAR1 = 1;
$VAR2 = [
          'hallo'
        ];
$VAR3 = {
          'hallo' => 1
        };
key=*a::x::y
$VAR1 = undef;
$VAR2 = [];
$VAR3 = {};

The first few lines until key=*a::x::y (excluding) are what was expected.

Now I wonder what is that "*a::x::y" key?


On the other hand the following code

$hallo::otto::otto=1;

no strict 'refs';
my $p="hallo::otto::";
${$p."klaus"}=2;

foreach my $k (sort keys %{$p}) {
  print "$k=".${${$p}{$k}}."\n";
}

shows only "klaus" and "otto" keys without "*hallo::otto::otto" and 
"*hallo::otto::klaus"

How are the *a::x::y objects created?

Torsten
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)

iD8DBQE/aFFCwicyCTir8T4RAphUAJ0XAQo+zazkc2tq+PpgVn054AgcnACgmQkq
e9v1oxY7+yu4DWBmv3eaEIE=
=xJwM
-----END PGP SIGNATURE-----

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About