Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

and anothe question

SouldrinkerSouldrinker Member Posts: 143
here I am...

I declare some packages in my new perl script ;-) fine thing, isn't it.

So - this packages have got different subroutines, for example one of the packages could look like this:

[code]

package testpackage;

sub test()
{
}

sub test2()
{
}

1;

Now I want to write a function "stat()" that reads out which functions are implemented in the testpackage, is it possible to do this? Is there some array where all the functions are saved?
best regards,

sebastian mohrenstecher
executive secretary
net::allies

www.net-allies.de
[email protected]

Comments

  • heeroyuyheeroyuy Member Posts: 125
    There is probably a variable you can access, i can look into it. Why do you wish to see which functions are available to call? Depending on what you need, there are other ways to do what your talking about, off hand none of them seem easy/worthwhile.
    -----------------------
    "The three principle virtues of a programmer are laziness, impatience, and hubris"

  • SouldrinkerSouldrinker Member Posts: 143
    yeah - thinked the same after one hour of working on that problem...

    it would be nice if a package is loaded and generates a "debug-logfile", to list which subfunctions are loaded, but... however - too complicated I guess ;)

    best regards,

    sebastian mohrenstecher
    executive secretary
    net::allies

    www.net-allies.de
    [email protected]

  • aspongeasponge Member Posts: 42
    : here I am...
    :
    : I declare some packages in my new perl script ;-) fine thing, isn't it.
    :
    : So - this packages have got different subroutines, for example one of the packages could look like this:
    :
    : [code]
    :
    : package testpackage;
    :
    : sub test()
    : {
    : }
    :
    : sub test2()
    : {
    : }
    :
    : 1;
    :
    : Now I want to write a function "stat()" that reads out which functions are implemented in the testpackage, is it possible to do this? Is there some array where all the functions are saved?

    If I'm clear as to what you're trying to do you need to use the Exporter module:

    package testPackage;
    require Exporter;
    our @ISA = qw(Exporter);
    our @EXPORT = qw(test
    test2
    others
    );

    sub test()
    {
    }

    etc...

    1;

    Then in any scripts that use testPackage the array @testpackage::EXPORT will give you any subroutines or variables you exported. Note placing symbols in @EXPORT will export them by default.

    Kevin
  • amokamok Member Posts: 1
    Since I'm not exactly sure what you want to do, I assume that you are making a routine which reads all the sub lines from certain package and then makes a list of them. You could simply either use grep under unix/linux to display all lines which contain "sub something()" or do a perl script which checks for each line, printing the ones which qualify with

    m/sub ([a-zA-Z0-9]+)/;

    Then you get the sub name saved to $1, so you could write something like this.

    open (PKG, "pkg.pl");
    @pkg = ;
    close(PKG);
    foreach $line (@pkg)
    {
    if ($line =~ m/sub ([a-zA-Z0-9]+)/)
    {
    print "Sub called $1 found";
    # do some other processing
    }
    }


    Or, to be really paranoid, you could always make the sub check more precise so it won't do false-positives. Adding a check so it's actually first word in that line would be a good thing. Adding another check to confirm that it really ends after the () part would also be nice. You might also want to save the parameters inside () for later review, so adding this might be a good idea as well.
  • Justin BibJustin Bib USAMember Posts: 0

    ______ [ http://forcoder.org ] free video tutorials and ebooks about { Delphi C# R Visual Basic C C++ JavaScript MATLAB Perl Go Ruby Objective-C Java PL/SQL Swift Visual Basic .NET Scratch Assembly PHP Python Rust Ada Prolog Clojure FoxPro Awk Crystal VBScript Dart LabVIEW Fortran Logo Hack Kotlin Lisp SAS COBOL ABAP Scala Julia Bash Alice D Scheme Erlang Transact-SQL F# Apex ML Lua } ______________

Sign In or Register to comment.