How to know from which perl module or file the function was called

Morad

I need to know from which perl file my function was called. Let's say I have the following module (MyModule.pm) which has the following function:

package MyModule;

sub myFunc{
   # Here I need to print the name of the file that the function was called from
}

And the script myScript.pl uses MyModule and calls the function myFunc():

use MyModule;
MyModule->myFunc();

I need the call to myFunc() here to print "myScript.pl"

Is there any way to do this in Perl?

Сухой27

Inside method,

sub myFunc{
  my ($package, $filename, $line) = caller;
  print $filename;
}

Check perldoc -f caller for more details.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Can I know the file and function names from where my function is called if it's from another .c?

分類Dev

Get element from which onclick function is called

分類Dev

SAS: how to know which Macro called current Macro?

分類Dev

SAS: how to know which Macro called current Macro?

分類Dev

How to determine which button called a function?

分類Dev

How to read a file which is gzipped and tar in perl

分類Dev

How do I know which method/class is called when I test java GUI in eclipse?

分類Dev

Function returning not defined when called from script file

分類Dev

How to know which mailFolder is the Inbox?

分類Dev

How to programmatically know if a module is a Core module?

分類Dev

How to pass index of array in cmd line argument which is function pointer and call to specific function in perl?

分類Dev

Is it possible to know in which method a file was encrypted?

分類Dev

Python package: Can I look for config/yml file from project directory which called it?

分類Dev

how to know if a file is empty or not

分類Dev

How can I know which item in a handlebars each loop triggered a function in my Ember controller?

分類Dev

Can't call a function from js file imported as type module

分類Dev

How does the xdg-open command know which application to use to open a file?

分類Dev

How can I mock a function called from a dictionary?

分類Dev

JS : How to pass value from module file to main file

分類Dev

How to know which font is used by browser from CSS font-family list?

分類Dev

How to include a module from another file from the same project?

分類Dev

How to simply output a binary file in Perl and read it from Android (Java)?

分類Dev

How to know which CharacterSet contains a given character?

分類Dev

How to know for which Master a Visio shape belongs to

分類Dev

how to know which JTextField is changed in a set of fields

分類Dev

How to know which ports are listened by certain PID?

分類Dev

How to know which utility installed a particular utility?

分類Dev

which value does javascript function takes if the function is called in the given example?

分類Dev

How to return which element from the tuple matched in the endswith function

Related 関連記事

  1. 1

    Can I know the file and function names from where my function is called if it's from another .c?

  2. 2

    Get element from which onclick function is called

  3. 3

    SAS: how to know which Macro called current Macro?

  4. 4

    SAS: how to know which Macro called current Macro?

  5. 5

    How to determine which button called a function?

  6. 6

    How to read a file which is gzipped and tar in perl

  7. 7

    How do I know which method/class is called when I test java GUI in eclipse?

  8. 8

    Function returning not defined when called from script file

  9. 9

    How to know which mailFolder is the Inbox?

  10. 10

    How to programmatically know if a module is a Core module?

  11. 11

    How to pass index of array in cmd line argument which is function pointer and call to specific function in perl?

  12. 12

    Is it possible to know in which method a file was encrypted?

  13. 13

    Python package: Can I look for config/yml file from project directory which called it?

  14. 14

    how to know if a file is empty or not

  15. 15

    How can I know which item in a handlebars each loop triggered a function in my Ember controller?

  16. 16

    Can't call a function from js file imported as type module

  17. 17

    How does the xdg-open command know which application to use to open a file?

  18. 18

    How can I mock a function called from a dictionary?

  19. 19

    JS : How to pass value from module file to main file

  20. 20

    How to know which font is used by browser from CSS font-family list?

  21. 21

    How to include a module from another file from the same project?

  22. 22

    How to simply output a binary file in Perl and read it from Android (Java)?

  23. 23

    How to know which CharacterSet contains a given character?

  24. 24

    How to know for which Master a Visio shape belongs to

  25. 25

    how to know which JTextField is changed in a set of fields

  26. 26

    How to know which ports are listened by certain PID?

  27. 27

    How to know which utility installed a particular utility?

  28. 28

    which value does javascript function takes if the function is called in the given example?

  29. 29

    How to return which element from the tuple matched in the endswith function

ホットタグ

アーカイブ