#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2014
    Posts
    15
    Rep Power
    0

    Calling Subs from modules confusion


    So I'm looking at some sets of code and I'm confused a bit about the way to call a subroutine from a module. It looks like this one script and set of modules just blindly calls subroutines and I thought it could be done better. These modules dont even contain the line '#!/usr/bin/perl' to start them, shockingly. The example below is a very shortened version of the nightmare. Overview follows:

    Code:
    -------------------
    Acct_manage.pl
    -------------------
    use Add;
    use Mat;
    
    ....code... 
    
    &Main_Menu
    
    -------------------
    Mat.pm
    -------------------
    sub Main_Menu{
       .....code.....
    }
    
    &Add_Acct;
    
    -------------------
    Add.pm
    -------------------
    sub Add_Acct{
       ....code....
    }
    As you can see from this when a module calls Add_Acct how are you supposed to know what pm file it came from so you gotta grep the directory to find it. Isn't it true that instead of that I could have something like this to make reading it easier or would this not do the same thing?

    Code:
    -------------------
    Acct_manage.pl
    -------------------
    use Add;
    use Mat;
    
    ....code... 
    
    Mat->Main_Menu();
    
    -------------------
    Mat.pm
    -------------------
    sub Main_Menu{
       .....code.....
    }
    
    Add->Add_Acct();
    
    -------------------
    Add.pm
    -------------------
    sub Add_Acct{
       ....code....
    }

    -Iconx
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2014
    Posts
    15
    Rep Power
    0
    Or am I thinking of this:

    Mat::Main_Menu();

    do both these methods require you to assign it to a variable?

    $q = Mat::Main_Menu();


    Originally Posted by Iconx
    So I'm looking at some sets of code and I'm confused a bit about the way to call a subroutine from a module. It looks like this one script and set of modules just blindly calls subroutines and I thought it could be done better. These modules dont even contain the line '#!/usr/bin/perl' to start them, shockingly. The example below is a very shortened version of the nightmare. Overview follows:

    Code:
    -------------------
    Acct_manage.pl
    -------------------
    use Add;
    use Mat;
    
    ....code... 
    
    &Main_Menu
    
    -------------------
    Mat.pm
    -------------------
    sub Main_Menu{
       .....code.....
    }
    
    &Add_Acct;
    
    -------------------
    Add.pm
    -------------------
    sub Add_Acct{
       ....code....
    }
    As you can see from this when a module calls Add_Acct how are you supposed to know what pm file it came from so you gotta grep the directory to find it. Isn't it true that instead of that I could have something like this to make reading it easier or would this not do the same thing?

    Code:
    -------------------
    Acct_manage.pl
    -------------------
    use Add;
    use Mat;
    
    ....code... 
    
    Mat->Main_Menu();
    
    -------------------
    Mat.pm
    -------------------
    sub Main_Menu{
       .....code.....
    }
    
    Add->Add_Acct();
    
    -------------------
    Add.pm
    -------------------
    sub Add_Acct{
       ....code....
    }

    -Iconx
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Apr 2009
    Posts
    1,875
    Rep Power
    1225
    Change:
    Code:
    Mat->Main_Menu();
    To:
    Code:
    Mat::Main_Menu();
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2012
    Posts
    781
    Rep Power
    495
    And, also, don't use this syntax to call a sub:

    Code:
    &Main_Menu
    This has been considered to be outdated for about 20 years. The right way to call s sub today is:

    Code:
    Main_Menu();

IMN logo majestic logo threadwatch logo seochat tools logo