G'day perlUser9,

You have an illegal prototype in "sub allVars($no1)":

$ perl -Mstrict -Mwarnings -e 'sub allVars($no1) { 1 }' Illegal character in prototype for main::allVars : $no1 at -e line 1.

See perlsub or, if that's too heavy going, start with "perlintro: Writing subroutines".

From the first line of code in &allVars:

my ($self, $no1, $no2, $name1, $name2) = @_;

I assume you're calling it something like this:

$object->allVars(...)

You seem to understand that all the arguments are in @_; and, you've assigned the first of those to $self. Why do then say "the arguments of allVars that is - $no1, $no2, $name1 and $name2"? What happened to $self?

I suspect you've misunderstood some key concept; unfortunately, I don't know what that might be. Also, this rather looks like an "XY Problem". Perhaps it would be better to explain your problem instead of your attempted solution.

My best guess at what you want (although I strongly suspect this guess is wrong) is along these lines:

#!/usr/bin/env perl -l use strict; use warnings; package Some::Module; sub new { bless {} => shift } sub all_vars { print "all vars = @_" } package main; my $obj = Some::Module::->new; $obj->all_vars(qw{a b c d});

Output:

all vars = Some::Module=HASH(0x7fc55c003098) a b c d

By the way, lexical variables don't live in the symbol table. If you were looking for them there, you won't find them.

-- Ken


In reply to Re: List arguments of a method by kcott
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.