Devel::ArgNames(3pm)
๐ Devel::ArgNames ๐
okay bestie, welcome to Devel::ArgNames โ it's a Perl module (a 3pm page, we love that for it), it lives in the User Contributed Perl Documentation, and it does exactly one gorgeous thing: it figures out the names of variables passed into subroutines. that's the whole vibe. ๐
โจ NAME โจ
Devel::ArgNames โ figure out the names of variables passed into subroutines. no cap, that's it, that's the job.
๐ธ SYNOPSIS ๐ธ
use Devel::ArgNames;
sub foo {
warn "foo() called with arguments: "
. join(", ", map { defined() ? $_ : "<unknown>" } arg_names(@_) );
}
foo($bar, $gorch, $blah[4]);
so like. you call arg_names(@_) and it just knows what the variables were called at the call site. it's giving psychic. ๐ฎ
๐ฆ DESCRIPTION ๐ฆ
okay so when you're print-debugging (we've all been there, no shame), you will often find yourself writing stuff like:
print "\$foo is $foo, \$bar is $bar"
and honestly? manually escaping all those \$ sigils is so tedious. exhausting. not the move. ๐ญ
with this module you can just write a reusable subroutine instead, effortlessly:
sub my_print_vars {
my %vars;
@vars{arg_names()} = @_;
foreach my $var ( keys %vars ) {
warn "$var is $vars{$var}\n";
}
}
my_print_vars($foo, $bar);
look at that. the variable names come for free from the caller's arguments. iconic behavior. ๐
real talk though: this module doesn't provide dumping facilities, because there are way too many of those to choose from and it's not about to pick favorites. it's a DIY kit ;-) so you build your own little printer and it hands you the names.
๐ EXPORTS ๐
arg_names [ $level ]โ this function returns the names associated with the variables it finds on@_, at the level$level. and if you don't pass$level? thenarg_names's caller's caller gets used โ which is the$level == 2case, for the people keeping score. ๐ฏ
๐ง VERSION CONTROL ๐ง
this module is maintained using Darcs. you can grab the latest version from http://nothingmuch.woobling.org/Devel-ArgNames/, and use darcs send to commit changes. old school but it works, okay? ๐ซถ
๐ฅ SEE ALSO ๐ฅ
Data::Dumper::SimpleDBDevel::CallerDevel::Caller::PerlPadWalker
go read those too, they're the friend group. ๐
๐ AUTHORS ๐
- Ran Eilam
- Yuval Kogman
<nothingmuch@woobling.org>
๐ COPYRIGHT ๐
Copyright (c) 2007 Yuval Kogman. All rights reserved
This program is free software; you can redistribute
it and/or modify it under the same terms as Perl itself.
okay and that's the whole page, bestie!! this little write-up is Devel::ArgNames(3pm), sitting in the User Contributed Perl Documentation, and the version living down at the bottom of the original is perl v5.36.0 from 2022-12-06. mwah. slay. periodt. ๐โจ๐
๐ฆ where this page comes from
- debian bookworm: libdevel-argnames-perl 0.03-3 ยท Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libdevel-argnames-perl 0.03-3 ยท Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libdevel-argnames-perl 0.03-3 ยท Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libdevel-argnames-perl 0.03-3 ยท Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libdevel-argnames-perl 0.03-3 ยท Artistic-1.0-Perl OR 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