B::Showlex(3pm)
okay bestie, welcome to the B::Showlex(3pm) page from the Perl Programmers Reference Guide β¨ this is the one about showing lexical variables used in functions or files, and weβre gonna read it together like a group chat. no cap.
π NAME π
B::Showlex β show lexical variables used in functions or files.
π SYNOPSIS π
the whole invocation vibe is:
perl -MO=Showlex[,-OPTIONS][,SUBROUTINE] foo.pl
πΈ DESCRIPTION πΈ
so hereβs the tea: when you give it a comma-separated list of subroutine names as options, Showlex prints the lexical variables used in those subroutines. Otherwise? It prints the file-scope lexicals in the file. thatβs the whole plot π
π¦ EXAMPLES π¦
Traditional form:
$ perl -MO=Showlex -e 'my ($i,$j,$k)=(1,"foo")'
Pad of lexical names for comppadlist has 4 entries
0: (0x8caea4) undef
1: (0x9db0fb0) $i
2: (0x9db0f38) $j
3: (0x9db0f50) $k
Pad of lexical values for comppadlist has 5 entries
0: SPECIAL #1 &PL_sv_undef
1: NULL (0x9da4234)
2: NULL (0x9db0f2c)
3: NULL (0x9db0f44)
4: NULL (0x9da4264)
-e syntax OK
New-style form:
$ perl -MO=Showlex,-newlex -e 'my ($i,$j,$k)=(1,"foo")'
main Pad has 4 entries
0: (0x8caea4) undef
1: (0xa0c4fb8) "$i" = NULL (0xa0b8234)
2: (0xa0c4f40) "$j" = NULL (0xa0c4f34)
3: (0xa0c4f58) "$k" = NULL (0xa0c4f4c)
-e syntax OK
New form, no specials, outside O framework:
$ perl -MB::Showlex -e \
'my ($i,$j,$k)=(1,"foo"); B::Showlex::compile(-newlex,-nosp)->()'
main Pad has 4 entries
1: (0x998ffb0) "$i" = IV (0x9983234) 1
2: (0x998ff68) "$j" = PV (0x998ff5c) "foo"
3: (0x998ff80) "$k" = NULL (0x998ff74)
Note that this example shows the values of the lexicals, whereas the other examples did not (as theyβre compile-time only). iconic behavior, honestly π«Ά
π OPTIONS π
-newlexβ this one produces a more readable"name => value"format, and itβs the one shown in the second example above. cute and useful, we love.-nospβ this one eliminates reporting of SPECIALs, like0: SPECIAL #1 &PL_sv_undefup above. Reporting of SPECIALs can sometimes overwhelm your declared lexicals, so this is the βokay bestie, breatheβ option π
π₯ SEE ALSO π₯
B::Showlex can also be used outside of the O framework, as in the third example. See B::Concise for a fuller explanation of reasons. iykyk π
π TODO π
Some of the reported info, such as hex addresses, is not particularly valuable. Other information would be more useful for the typical programmer, such as line-numbers, pad-slot reuses, etc.. Given this, -newlex is not a particularly good flag-name. we said what we said π
π AUTHOR π
Malcolm Beattie, "mbeattie@sable.ox.ac.uk"
mwah π β this page is from perl v5.42.3, dated 2026-11-03. periodt.
π¦ where this page comes from
- alpine 3.24: perl-doc 5.42.3-r0 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms