Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Ah, the joys of debugging global variables! Iron-clad employment insurance!! You'll be working on this until the end of time — or until the company goes under, not unlikely if they've got a lot of code like this.

Here's one approach, not necessarily the best: track down the package the hash lives in (assuming it's a package global):

c:\@Work\Perl\monks>perl -wMstrict -le "no strict qw(refs vars); no warnings; ;; package Foo; %CONTACTS = ('hello' => 'sailor'); ;; package Bar; $ZOT{'autovivified'} = 'bam'; ;; package main; ;; my $rx_pkg = qr{ \A (?: [[:alpha:]] [[:alnum:]]* ::)+ \z }xms; ;; print qq{'$_'} for grep m{ $rx_pkg }xms, keys %main:: ; print ''; ;; print qq{'$_' has 'CONTACTS'} for grep exists ${$_}{CONTACTS}, grep m{ $rx_pkg }xms, keys %main:: ; print ''; ;; print qq{'$_' has 'ZOT'} for grep exists ${$_}{ZOT}, grep m{ $rx_pkg }xms, keys %main:: ; print ''; ;; print $Foo::CONTACTS{'hello'}; print $Bar::ZOT{'autovivified'}; " 'version::' 'utf8::' 're::' 'CORE::' 'DynaLoader::' 'mro::' 'strict::' 'Win32CORE::' 'Bar::' 'Regexp::' 'UNIVERSAL::' 'Foo::' 'main::' 'Carp::' 'Win32::' 'PerlIO::' 'IO::' 'Exporter::' 'Internals::' 'warnings::' 'DB::' 'Foo::' has 'CONTACTS' 'Bar::' has 'ZOT' sailor bam
Note that:
  • This code only runs if some strictures are disabled (no strict qw(refs vars);) — and it doesn't hurt to disable warnings also — you may have to turn all these off locally;
  • This shows the package the hash lives in, but how it got there is another story;
  • The example code shows hash definition in Foo, autovivification in Bar. For your purposes, they amount to the same thing.

Updates:

  1. Added
        no strict qw(refs vars);
        no warnings;
    statements to example code.
  2. Check out Packages and Symbol Tables in perlmod.
  3. Actually, on re-reading the docs, I think
        my $rx_pkg = qr{ \A (?: [[:alpha:]_] \w* ::)+ \z }xms;
    would be a better definition of the package name regex.


Give a man a fish:  <%-(-(-(-<


In reply to Re: Finding Location of Hash Structure? by AnomalousMonk
in thread Finding Location of Hash Structure? by mdskrzypczyk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2024-04-25 23:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found