Hi,

I cannot seem to figure out why my use of a hash of hash doesn't work when I integrate my test script into a Object Orientated Perl module.

Here's an abbreviated version of my test script:

#!/usr/bin/perl -w use strict; my %TZMap = ( sjc => { TZ1 => 'PST', TZ2 => 'PDT', TZFILE => '/usr/share/zoneinfo/America/Los_Angeles', }, blr => { TZ1 => 'IST', TZ2 => 'IST', TZFILE => '/usr/share/zoneinfo/Asia/Calcutta', }, ); sub testmap { my $tz = `/bin/date +%Z`; chomp($tz); my $site = `/bin/hostname | cut -d- -f2 | cut -c1-3`; chomp($site); my $tzfile = $TZMap{$site}->{TZFILE}; print "$site:" . $TZMap{$site}->{TZ1} . ":" . $TZMap{$site}->{ +TZ2} . ":$tz\n"; } testmap();
The output of this is what one would expect:
sjc:PST:PDT:PST
Now I moved this same declaration of the TZMap into a Perl module where I hope to check systems' timezone info like so ...
package MAN::ER::SRole::Base; use strict; use base qw(MAN::ER::SRole); use MAN::ER::SRole; ... code omitted ... my %TZMap = { ... code omitted ... }; ... code omitted ... sub new { my $proto = shift; my $class = ref($proto) || $proto; my $self = $class->SUPER::new(); bless($self, $class); return $self; } ... code omitted ... sub check_timezone { my ($self) = @_; my $site = `/bin/hostname | /bin/cut -d- -f2 | /bin/cut + -c1-3`; chomp($site); my $tz = `/bin/date +%Z`; chomp($tz); my $tzfile = $TZMap{$site}->{'TZFILE'}; print Dumper(%TZMap); print "$site:" . $TZMap{"$site"}{TZ1} . ":" . $TZMap{$site}->{ +TZ2} . ":$tz\n"; if ( $TZMap{$site}->{TZ1} eq $tz or $TZMap{$site}->{TZ2} eq $t +z ) { $self->log_okay_message( "yada yada\n"); } else { $self->log_error_message("blah blah\n" ); } } sub check { my ($self) = @_; $self->clear_result(); $self->_common('check'); $self->ensureprocess($_) foreach @processes; $self->check_timezone(); }
When I run the code that uses this Perl module the output I get is ...
$VAR1 = { 'HASH(0x88eb640)' => undef, 'sjc' => {} }; sjc:::PST
... there are no values in the has. What am I doing wrong here? and BTW we are using a vert old version of Perl (v5.6.1) maybe that's the issue but I hope not.

In reply to What happened to my globally declared hash when moved to OO Perl code? by Plankton

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.