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


In reply to Re: List arguments of a method by davido
in thread List arguments of a method by perlUser9

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.