Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Hi to all. I'm a perl rookie and I started to struggle creating my own modules. I'm having a question that I cannot answer by myself and I ask for your Wisdom to trow some light on my dilemma.
Lets say that I create a module Foo.pm, which has "new" sub.
package Foo; sub new { my ($class) = @_; my $self = {}; bless $self, $class; }
And, I have my script test.pl which has:
use Foo; my $one = Foo->new; my $second = Foo->new;
And my question is: Is there a way that I can, inside Foo.pm, know the name of the variable that I'm using on test.pl?
Lets say I want to create a sub on Foo.pm that just returns the name of $one or $second.
Note that I need this to be able to catch and display my own custom warnings on Foo.pm and I want to give the name of the variable that caused the warning when printing on screen the warning message.
I hope my question is clear enough. I'm not a good english speaker so please excuse any error on the writing. Thanks in advance for any help or comment about this.

In reply to Variable Name Mistery. Who calls? by porta

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2024-04-19 22:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found