CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Stange Module behaviour

 



Iconx
Novice

Mar 6, 2014, 12:12 PM

Post #1 of 2 (1805 views)
Stange Module behaviour Can't Post

I'm Cross-posting this on DevShed and perlmonks for some more feedback. You never know when someone will have more information to jolt an idea. I got a good response on perlmonk and I see that it has to be re-written, just trying to be more incremental about it, theres alot to this app.
-------------- cut ------------

Hello, I've got a strange possibly obvious problem here. I'm trying to cleanup a perl application and I'm not getting the variable passed to another module for some reason. This thing is kind of a maze but its getting better. Heres a brief rundown:


Code
mat.pl 
--------------
use lib "lib";
use Utility;
use Add;
use Group;

Add::Add_Acct();
</code>

<code>
lib/Add.pm
--------------
package Add;
### I tryed exporter here with no luck, maybe I did it wrong? ###

require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw($USERID);

sub Add_Acct
{
print "Adding an Account";
&ID;
&LAST ;
&FIRST; ##a prior dev did this sub calling, its crap I know ###
&USERID; ##This sub takes user input ##
print "ID: $ID - UserID: $USERID \n"; ## All vars defined and as expected here ##
Group::Groups();
....
...
</code>

<code>
lib/Group.pm
-------------------
package Group;
sub Groups
{
print "ID: $ID - USERID: $USERID \n";
### $ID is ok but $USERID is undefined ##
....
.....
}
</code>

<code>
sub USERID
{
$USERID = Utility::Single_Input('Input Account Name', $USERID, $REQUIRED);
print "UserInput entered is $USERID \n";
}


Ok so a main program Mat.pl calls the Add.pm module which loads some variables from other subroutines and then calls another module, Group.pm . Right before it calls the other module both $ID and $USERID are defined and good. Once it gets into the Group module the $USERID variable is not defined, its just empty yet $ID seems ok. Whats going on here. Maybe I should add that the &USERID subroutine takes user input, but the user input is returned just fine to the Add_Acct sub and its defined right before the call to Groups.

What am I missing here?


(This post was edited by FishMonger on Mar 6, 2014, 1:01 PM)


FishMonger
Veteran / Moderator

Mar 6, 2014, 1:10 PM

Post #2 of 2 (1798 views)
Re: [Iconx] Stange Module behaviour [In reply to] Can't Post

Difficult to say what the problem is with such incoherent code and description.

Please reduce your code down to a small set that compiles and demonstrates your problem. That will allow us to test your code, if needed, and tell you whats wrong.

One major problem I do see in your posted code is that it's missing:

Code
use strict; 
use warnings;


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives