in reply to List arguments of a method

If ever I say something is impossible someone will come along and show that with a CPAN module I've previously been unaware of, deep XS magic, or a crazy source filter an implementation of just that is possible and exists. So I won't say this is impossible.

However, consider the limitations, and more importantly, reconsider why you need this. It seems that what you are asking is not to determine what parameters were passed, but instead, how they were passed. You don't want to know that the first param was "foo", you want to know that a variable named $bar was used to pass it in.

But you have no guarantees that the value was passed by a single scalar variable. Consider the following examples:

my $val = "foo"; my $valref = \$val; my @valarray = ("foo"); my %valhash = ( somekey => 'foo' ); my %otherhash = ( foo => 'dummy_value' ); allvars($val); allvars($$valref); allvars($valarray[0]); allvars(@valarray); allvars("foo"); allvars(join '', map { chr } (102,111,111)); allvars($valhash{somekey}); allvars(keys %otherhash);

All of these sub calls will hold 'foo' in $_[0], but what would you hope to learn by inspecting how the value was passed to the sub?

This is certainly an XY problem. Is it possible that you just want a way of doing named parameters? This can be facilitated by passing a hash or hashref:

my $params = { this => 'foo', that => 'bar', other => 'baz', } sub param_names { my $params = shift; print "$_: $params->{$_}\n" for keys %$params; } param_names($params);

(Ignoring prototypes, because there's still an impedance mismatch between what it seems is wanted here, and what they provide)


Dave