```{index} single: peek_my; PadWalker function ``` ```{index} single: PadWalker::peek_my; Perl function ``` # peek_my Return every `my` variable in scope at a given call-stack depth as a hash of name-to-reference pairs. ## Synopsis ```perl use PadWalker qw(peek_my); my $h = peek_my($level); ``` ## What you get back A hash reference. Each key is a variable name *with* its sigil — `'$x'`, `'@list'`, `'%env'`. Each value is a reference to the live variable, so dereferencing and assigning through it changes the original. `our` variables are not included; use `peek_our` for those. ## Examples Read a `my` variable in the current scope: ```perl my $x = 12; my $h = peek_my(0); print ${ $h->{'$x'} }; # 12 ``` Modify the caller's `my` variable: ```perl sub bump_x { my $h = peek_my(1); ${ $h->{'$x'} }++; } my $x = 5; bump_x(); print $x; # 6 ``` A `my` declared deeper than the target frame is not in the returned hash — only variables visible at the call site come back. ## Edge cases - `$level` defaults to `0` if omitted. - `$level` deeper than the call stack croaks with `Not nested deeply enough`. - Negative `$level` is not supported and croaks. - Variables declared inside an `eval BLOCK` between the target frame and the call site are folded in at the sequence number of the call — they become visible alongside the target's own lexicals. ## Differences from upstream Fully compatible with upstream PadWalker {{ upstream.PadWalker }}. ## See also - `peek_our` — same idea for `our` variables. - `peek_sub` — inspect a CV's pad directly, without walking frames. - `var_name` — given a reference, find the name it had in a pad.