B::Showlex(3perl)
π B::Showlex β the Perl Programmers Reference Guide bestie edition π
okay so you know how you're staring at your Perl code like "where tf do my lexicals even live"?? that's literally what B::Showlex(3perl) is for and she eats every time. she's part of that whole B:: backend universe and bby she will show you the lexicals. no cap.
β¨ NAME β¨
B::Showlex β Show lexical variables used in functions or files π¦
β¨ SYNOPSIS β¨
perl -MO=Showlex[,-OPTIONS][,SUBROUTINE] foo.pl
β¨ DESCRIPTION β¨
so here's the vibe π β when you hand it a comma-separated list of subroutine names as options, Showlex prints out the lexical variables that get used inside those subroutines. cute.
otherwise? she prints the file-scope lexicals in the file instead. either way you're getting the tea π
β¨ EXAMPLES β¨
πΈ the 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
π the 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 the 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)
lowkey important: this third example actually shows you the values of the lexicals, whereas the other examples did not (because those are compile-time only). iykyk π
π OPTIONS
-newlexβ this one gives you a way more readable"name => value"format, and you can peep her in the second example up above β¨-nospβ this one kills the reporting of SPECIALs, like0: SPECIAL #1 &PL_sv_undeffrom the example above. real talk, SPECIAL reporting can sometimes just completely overwhelm your declared lexicals π
β¨ SEE ALSO β¨
B::Showlex can also be used outside of the O framework, just like in the third example bestie. and if you want the full explanation of the reasons and the whole lore? see B::Concise π
β¨ TODO β¨
ngl some of the stuff she reports β hex addresses and whatnot β is not particularly valuable π other info would be way more useful for the typical programmer, like line-numbers, pad-slot reuses, etc.. and given all that, -newlex is honestly not a particularly good flag-name. we said it. π
β¨ AUTHOR β¨
Malcolm Beattie, "mbeattie@sable.ox.ac.uk" π
okay and one last thing bestie, so you have the receipts: this was perl v5.44.0, dated 2026-10-17, and it's the B::Showlex(3perl) page from the Perl Programmers Reference Guide. slay π«Άβ¨π
π¦ where this page comes from
- arch rolling: perl 5.44.0-1 Β· Artistic-1.0-Perl AND GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms