how to get the caller's information?

Discussion in 'Perl Misc' started by Brady, Jul 15, 2006.

  1. Brady

    Brady Guest

    hi, all,

    i want to have a sub debug, which takes a string as a parameter, and
    print the file name and line number of the place invoking the sub.

    I tried to :
    in main.pl:

    if ($something_is_wrong) {
    Mylib::Debug("wrong!!!");
    }

    in Mylib.pm

    sub Debug()
    {
    print STDERR, "__FILE__:__LINE__", @_;
    }

    but, the __FILE__ and __LINE__ is the Mylib.pm and the line number of
    Mylib.pm.

    how to get the caller's place?


    thanks & best wishes!

    /Brady
    Brady, Jul 15, 2006
    #1
    1. Advertising

  2. Brady

    brian d foy Guest

    In article <>,
    Brady <> wrote:


    > how to get the caller's place?


    have you tried the caller() builtin?

    perldoc -f caller

    --
    Posted via a free Usenet account from http://www.teranews.com
    brian d foy, Jul 15, 2006
    #2
    1. Advertising

  3. Brady

    DJ Stunks Guest

    Brady wrote:
    > hi, all,
    >
    > i want to have a sub debug, which takes a string as a parameter, and
    > print the file name and line number of the place invoking the sub.
    >
    > I tried to :
    > in main.pl:
    >
    > if ($something_is_wrong) {
    > Mylib::Debug("wrong!!!");
    > }
    >
    > in Mylib.pm
    >
    > sub Debug()
    > {
    > print STDERR, "__FILE__:__LINE__", @_;
    > }
    >
    > but, the __FILE__ and __LINE__ is the Mylib.pm and the line number of
    > Mylib.pm.
    >
    > how to get the caller's place?


    use Carp;

    -jp
    DJ Stunks, Jul 15, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?SG1udA==?=
    Replies:
    5
    Views:
    2,632
    IcingDeath
    Jun 25, 2006
  2. ABC
    Replies:
    1
    Views:
    417
    DavidG
    Jan 13, 2006
  3. popov
    Replies:
    2
    Views:
    338
    popov
    Dec 10, 2003
  4. David
    Replies:
    9
    Views:
    3,768
    David
    Sep 14, 2006
  5. Mark
    Replies:
    2
    Views:
    385
Loading...

Share This Page