in reply to typeglob & my | our

my %foo creates a lexical PAD entry. our %foo creates a stash, with %foo a lexically scoped name for the hash entry in said stash.

*foo is that stash (imagine lots of hand waving here).

When you later to keys %foo, Perl first goes hunting in the PAD for a lexical hash, if not found, it looks in the stash. In the variant you're doing my %foo, Perl will take the one from the PAD, which is empty. Without the my %foo Perl finds the %foo you want.

Could someone please explain why the "my" version is good enough to make Perl happy while still returning an unexpected result?
If you mean by "making Perl happy", "strict doesn't throw an exception", do realize that strict isn't an magic bullet. Strict is like having a car whose motor will not start if your door isn't closed, and your seat belts aren't locked when turning the key. Warnings are the beeping sounds your car will make as soon as you drive above 55 miles per hour. Neither of them prevents you from running full speed into a tree, or ending up in the Bronx while your intention is to go to Vegas.

Replies are listed 'Best First'.
Re^2: typeglob & my | our
by LanX (Saint) on Mar 07, 2012 at 14:40 UTC
    > *foo is that stash

    hmm ... in my terminology *foo is a _typeglob_ for the _symbol_ foo having slots for variables like %foo or $foo.

    But the STASH (= symbol table hash) is the surrounding hash (associated to a package e.g. %main::) holding such symbols.

    see also "symbol table" in perlglossary

    Cheers Rolf

    UPDATES: added link and "slot"-part

      Imagine that while I'm doing the indicated handwaving, LanX is in one of my hands.
        > ... LanX is in one of my hands.

        Almost! But could you now please pull your hand out of my guts?

        Cheers Rolf