in reply to Uninitialized or not?

I suspect that the first case is considered "left-hand context", that is, potentially "being assigned to", which triggers autovivification while the second case is purely "right-hand context" (just getting the value) and so doesn't trigger autovivication.

This makes some sense since you can assign to $_ inside of the foreach, but I'm not a big fan of the way it works.

I'd rather just have an option like strict that just turns off all autovivification (it requires a bit more careful coding but can also catch certain types of coding errors for you -- and I prefer that style of coding, it making the intent clearer).

Update: How did you get the impression that I was proposing anything other than that, Aristotle? strict is disabled by default. "turns off" also implies that autovification being "on" would be the default.

        - tye

Replies are listed 'Best First'.
Re^2: Uninitialized or not?
by Aristotle (Chancellor) on Nov 27, 2002 at 19:21 UTC
    Autovivification is very handy on occasion - but can get in the way also. Seeing as the very most of the time I want the DWIM behaviour (sometimes I outright rely on it), I'd prefer this stricture to be off by default but available to whomever wants to enable it on a scope-by-scope basis (exists $key{doesnt_exist}{this_neither} comes to mind).

    Makeshifts last the longest.