in reply to Using Data::Dumper with a HoH

You're putting your data into a hash called %hash. But you're trying to print out the contents of a scalar called $hash.

use strict is your friend.

--
<http://dave.org.uk>

"The first rule of Perl club is you do not talk about Perl club."
-- Chip Salzenberg

Replies are listed 'Best First'.
Re^2: Using Data::Dumper with a HoH
by bart (Canon) on Oct 30, 2006 at 11:50 UTC
    Good call.

    I was first thinking of another pitfall you have to watch out for, at least with strict off, and that is when while populating the hash, some entries may not be a ref or undef, but a string. In that case, Perl will go weird on you. For example:

    use Data::Dumper; no strict; %hash = ( a => 'x123' ); $hash{a}{b} = 'data'; print Dumper \%hash;
    which produces:
    $VAR1 = { 'a' => 'x123' };
    So, where did your data go to? It went into the global variable %x123, via a symbolic reference ${$hash{$a}}{b}.
    print Dumper \%hash, \%x123;
    produces
    Name "main::x123" used only once: possible typo at Z:\test.pl line 6. $VAR1 = { 'a' => 'x123' }; $VAR2 = { 'b' => 'data' };
    The "used only once" warning is a compile time warning, but using the symbolic reference (once) doesn't produce any warnings at all.
Re^2: Using Data::Dumper with a HoH
by chinamox (Scribe) on Oct 30, 2006 at 11:55 UTC

    *head strikes desk*

    Thanks for the hand. I will not wander from 'use strict' again! The printout is beautiful:)

    -mox