http://www.perlmonks.org?node_id=991188


in reply to Inspecting the name of a variable

From the manual entry for 'for':

Foreach Loops

The foreach loop iterates over a normal list value and sets the variable VAR to be each element of the list in turn. If the variable is preceded with the keyword my, then it is lexically scoped, and is therefore visible only within the loop. Otherwise, the variable is implicitly local to the loop and regains its former value upon exiting the loop. If the variable was previously declared with my, it uses that variable instead of the global one, but it's still localized to the loop. This implicit localization occurs only in a foreach loop

Replies are listed 'Best First'.
Re^2: Inspecting the name of a variable
by LanX (Saint) on Sep 01, 2012 at 20:18 UTC
    Well ... RTFM doesn't explain anything. =)

    localized variables are propagated into any called subs.

    apparently PadWalker is missing a pad to investigate or should extend it's documentation.

    UPDATE: ... well only if aliases have a pad...

    UPDATE: yes it's because of the aliasing:

    our $orig=666; for our $x (42,$orig) { say $bar,our_name($bar); say $x,our_name($x); }

    10$bar 42 10$bar 666$orig

    Cheers Rolf

      Hello

      I found Data::Dumper::Names with this thread . In this manual of Data::Dumper::Names, there is "Unknown Variables" section.

      "Unknown Variables" section seems to me having some relation with your case... not printing name "$x".

      update:
      Sorry if I am looking into wrong direction.
        Thats where I started, but if you look into Ovid's code you will see that he's only inspecting lexical variables.

        Cheers Rolf