lexicals
view release on metacpan or search on metacpan
lib/lexicals.pod view on Meta::CPAN
Just say:
my $hash = lexicals;
Assuming you have a $foo and $bar defined, you get the same thing.
The C<lexicals> module exports a function called C<lexicals>. This function
returns the lexicals as a hash reference (in scalar or list context).
=head1 ARRAYS AND HASHES
The above examples deal with lexical scalars. You can also get back lexical
arrays and hashes. Note: since there is no sigil to tell scalars from arrays
from hashes, you can't get back a scalar and an array or hash of the same
name. In this case, SCALAR beats HASH beats ARRAY. Why? Because I said so!
(Actually I just used the sort order of the sigils).
sub foo {
my %h = ( O => 'HAI' );
my @a = [ qw( foo bar baz ) ];
my $s = 42;
my %x = ( O => 'HAI' );
my @x = [ qw( foo bar baz ) ];
my $x = 42;
print Dump lexicals;
}
would yield:
---
a:
- foo
- bar
- baz
h:
O: HAI
s: 42
x: 42
=head1 NOTE
The C<lexicals> function only reports the lexical variables variables that
were defined before where it gets called.
=head1 DEBUGGING TRICK
This could be a handy idiom for debugging:
use XXX;
sub foo {
...
XXX lexicals; # See your lexicals in the nude.
...
}
=head1 SEE ALSO
=over
=item * L<PadWalker>
=item * L<Acme::Locals>
=item * L<XXX>
=back
=head1 AUTHOR
Ingy döt Net <ingy@cpan.org>
=head1 COPYRIGHT AND LICENSE
Copyright 2011-2015. Ingy döt Net.
This program is free software; you can redistribute it and/or modify it under
the same terms as Perl itself.
See L<http://www.perl.com/perl/misc/Artistic.html>
=cut
( run in 0.409 second using v1.01-cache-2.11-cpan-d7f47b0818f )