in reply to Perl Modules
Hello jamroll,
Your description is very open, you are saying that you have all these modules that you are trying to call. Did you implement all these modules yours self? Do you have a main script eg. main.pl that calls the modules in the directory?
For example pseudo code main.pl
#!usr/bin/perl use strict; use warnings; use pm::security; print banned(...); # This is how you are calling the method and you ar +e getting the error?
How you export your methods? Have you read Simple Module Tutorial
We need to see at least one module and how you have define it, how you are calling it and see why you are not able to access your methods.
Provide us all these data with well formatted output and we will be more that happy to provide assistance.
Update: Sample of your module to get you started:
Perl module (Security.pm) inside your directory Pm. Path to the module is (local dir of main.pl module Pm/Security.pm)
package Pm::Security; use strict; use warnings; use Exporter; use vars qw($VERSION @ISA @EXPORT_OK); $VERSION = 1.00; @ISA = qw(Exporter); @EXPORT_OK = qw(banned); sub banned { return reverse @_ } 1;
Main module (main.pl)
#!usr/bin/perl use say; use strict; use warnings; use Pm::Security qw( banned ); # use Benchmark qw(:all) ; # WindowsOSn # use Benchmark::Forking qw( timethese cmpthese ); my @list = qw (First ~ Second); say banned( @list ); __END__ $ perl main.pl Second~First
Hope this helps, BR
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Perl Modules
by jamroll (Beadle) on Jun 20, 2017 at 20:58 UTC | |
| [reply] |
|
Re^2: Perl Modules
by jamroll (Beadle) on Jun 20, 2017 at 18:34 UTC | |
alright. i'll post some code. the relevant stuff. it'll be large, i'm sure...that's why i didn't post code in the first place. i'm seeking general information - problem is i can't articulate into words what I'm having difficulty with. with that said, it is imperative i figure this out, so i'll do exactly what you guys need to help me, and i will pay great attention. oh! let me just say this - jargon often escapes me. simple jargon doesn't, but if the jargon starts getting real technical, jamroll tends to get lost...so i adhere to the KISS principle like flies on ... stuff. i may redact some areas of the code for security purposes. i'll point out that i don't use caps very often, as you can see. i don't much care to hit shift that much. i recognize the convention is to upcase the first char of a module (Security instead of security, for example) - but is that just a convention, or a hardcoded rule? all of the modules in pm:: are my own creation! the modules are stored in D:/Apache24/htdocs/pm/
i try to avoid having to use other's packages (that requires learning their way, and since i'm so very deep into this project, incorporating something new would be an entirely grandiose endeavor - no, i'm kinda stuck with the structure i'm laying out here) so, firstly, this is the error message i get (happens everywhere, too - not JUST with this example): so here's the ALL of the code that is generating this error (like i said, this could be big) user.pm - d:/apache24/htdocs/pm/user.pm and related code for the function calls within the above module's sub. which are: sql_execute, user_exists, and banned pm::bc_sql::sql_execute(...) is my own flavor of the execute command (and i'm certain, nay, i know it's is badly done) - but it works! so, it stays as is for nowbc_sql.pm - d:/apache24/htdocs/pm/bc_sql.pm security.pm - d:/apache24/htdocs/pm/security.pm
i think that covers the meat of it... i have removed all use pm::xxx; statements in the actual code, and just copied it to here. i have also tried removing pm::xxx:: before my function calls when the corresponding module has "use pm::xxx;" in it. i get the same error as what's above in other places (not just ::banned does exist - but sometimes sql_execute doesn't exist). it's all very very confusing to me. i don't understand even why the error message appears...and sorry it took so long to reply. had to make sure i covered my bases, dotted my T's and crossed my eyes! | [reply] [d/l] [select] |
by poj (Abbot) on Jun 20, 2017 at 19:40 UTC | |
Here is a very simple script and module to demo the principles. First a module with 1 subroutine
and a script that uses it poj | [reply] [d/l] [select] |
by jamroll (Beadle) on Jun 20, 2017 at 20:08 UTC | |
and, i noticed i forgot to post my main code, which may be relevant (or critical even?) to my module confusion debug.pl - d:/apache24/htdocs/debug.pl oh! and i guess you could use a _test() function, too for the example i'm showing. hopefully i've covered it all finally...if i missed something, do let me know, i'll post it. but i gotta get this solved. i totally get how to use a single pm. i'm wondering why i get these silly errors.... security.pm - d:/apache24/htdocs/pm/security.pm
| [reply] [d/l] [select] |
by poj (Abbot) on Jun 20, 2017 at 20:43 UTC | |
by jamroll (Beadle) on Jun 20, 2017 at 20:54 UTC | |
by thanos1983 (Parson) on Jun 20, 2017 at 20:49 UTC | |
Hello again jamroll, Let's take the question one at a time. Why you should use Package name as first letter capital? Read the perlman:perlstyle: From the link above regarding the packages:
Having said that I would recommend renaming the directory to Pm/Security the same applies to the rest of the modules that you are using. Let's move on to the next problem, calling the module. You are saying that you have a main.pl script that gives you the error:
Let's try to replicate the problem. I am creating the directories as you say d:/apache24/htdocs/pm/user.pm I would modify a bit your module so I would recommend to do the same on the rest of your modules. First of all I use also use warnings; for many reasons make your code more safe. Second from the Perl documentation Exporter/Selecting What to Export:
Having said that I modify your Export to Export_OK. On your modules you need to close them with 1;. Why? Read the perlmod/Making your module threadsafe:
If this is not enough also read Perl Module ending without 1;. Having said that I add also 1; at the end of your module. Sample of your module based on the modifications that I propose Security.pm in the directory of my local PC /home/tinyos/apache24/htdocs.
Now that we have defined and applied minor modification to your module let's try to call it for execution from our main.pl: Sample of main.pl script, remember the path is relevant to my local PC but it should work for your PC with minor modifications:
A minor detail to add here I call the script from a different directory where the dir Pm is located. I manage to do that by using the lib module. If I comment out this line # use lib '/home/tinyos/apache24/htdocs'; I get the following expected error:
Of course it is because Perl is not aware of my Pm::Security module that I have defined in my directory. One last question, why you are calling your function as sub banned($$) I was looking online regarding this because I never used it before and I found perlvar/General Variables:
If this is the case why don't you call getppid instead of $$. Maybe I am wrong regarding this point so another Monk could share some knowledge. Hope this provides you enough information to resolve all of your module(s) problems.
Seeking for Perl wisdom...on the process of learning...not there...yet!
| [reply] [d/l] [select] |
by jamroll (Beadle) on Jun 21, 2017 at 05:45 UTC | |
the module Pm::Bc_chef doesn't like having use Pm::User; in it. Well, it actually causes Pm::User to throw the "subroutine not defined" error message (because use Pm::Bc_chef; is in the module Pm::User. so, if chef needs to refer to a user module subroutine, i can't put use Pm::User; in Bc_chef.pm. baffling, but it's working. so grateful JamRoll Btw - is my coding awful? i've always wondered, and hoped you folks might be willing to grade it without killing my itty bitty ego too much... ;) is there more of my code you would like to see? i can let you peek under the hood, so to speak, to get a better feel for how i go about doing things. i'd really like some constructive input on it, too....i know it's way off topic here, so perhaps PM me...I'll be on and off fairly often, doing my (re)search(es). | [reply] [d/l] [select] |
by AnomalousMonk (Archbishop) on Jun 21, 2017 at 06:59 UTC | |
by jamroll (Beadle) on Jun 21, 2017 at 18:23 UTC | |
by tobyink (Canon) on Jun 21, 2017 at 18:45 UTC | |
by jamroll (Beadle) on Jun 20, 2017 at 22:10 UTC | |
| [reply] [d/l] [select] |
by Discipulus (Canon) on Jun 21, 2017 at 06:25 UTC | |
by jamroll (Beadle) on Jun 20, 2017 at 23:24 UTC | |