in reply to (another) HoH question

Add the following two lines in fromt of your code:

use strict; use warnings;

Run your script. It will complain loudly that variables need explicit package names.This mostly says that your code lacks my in front of the loop variables.

Add the three mys. Run your script again. Look at the error messages and your code. Compare what you meant with what you really wrote.

Alexander

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

Replies are listed 'Best First'.
Re^2: (another) HoH question
by zuma53 (Beadle) on Jun 23, 2012 at 18:14 UTC
    Almost there.

    I added 'my %hash', and it cleared up the error in the assignments. But it still complains about '$hash->{$key}'. I thought this was covered in 'my %hash' as isn't $hash-{$key} pointing to %hash? What am I missing?

    Thanks!
      ... isn't  $hash-{$key} pointing to  %hash? What am I missing?

      You're missing the point that the expressions  $hash{foo} and  $hash->{foo} refer to different and quite separate hashes.

      >perl -wMstrict -le "my %hash = ( foo => 'bar' ); my $hash = { foo => 'not_bar_at_all' }; ;; print qq{what is foo? $hash{foo}}; print qq{what is foo? $hash->{foo}}; " what is foo? bar what is foo? not_bar_at_all
Re^2: (another) HoH question
by tobyink (Canon) on Jun 23, 2012 at 18:16 UTC
    Absolutely irrelevant. The issue at hand has absolutely nothing to do with "use strict".
    perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'