Yes. These files are called script_name.pm with their first line containing package main; and every module that is being written is being called from the main script as use script_name. Now, I realize that this i s just basicly placing the namespace of each script into main:: which is fine but I am still not clear why my subs are being run at compile time.
Here is a portion of my code:
38 my %sn; # temporary 39 $sn{chanserv} = "ChanServ"; # temporary 40 41 my $_name = $sn{chanserv}; 42 my($_source,$_data) = (shift,shift); 43 44 $_data = &_cs_parse_raw_cmd($_data) if $_data; 45 &_sendit($_name,$_source,$_data); 46 47 # ************************************************************ 48 # sub routines 49 # ************************************************************ 50 51 # *** 52 # _send_it(): simple wrapper for chanserv to send data 53 # through the main socket. 54 # *** 55 56 sub _sendit 57 { 58 my $_channel = shift; 59 my $_message = shift; 60 61 # send_data(':%s ! %s :%s', $_name, $_channel, "I saw your + message: $_message"); 62 printf(":%s ! %s :%s\n", $_name, $_channel, "I saw your m +essage: $_message"); 63 } 64 65 66 # *** 67 # _cs_parse_raw_cmd() : parses out raw data from main destined 68 # for chanserv. This will parse the raw packet. 69 # *** 70 71 sub _cs_parse_raw_cmd 72 { 73 my ($cmd) = @_ ; 74 75 # Chanserv :test 76 # ChanServ@Services.Netfrag.Com :test 77 78 my ($_to_whom, 79 $_message) = split(/:/,$cmd); 80 81 # First, make sure that we are the right one getting call +ed 82 unless ( /\#/ ) { 83 if ( lc($_to_whom) !~ m/$_name/i ) { 84 &sendit($_source,"Please let an admin know that s +omething is broke."); 85 } 86 } 87 88 return($_message); 89 } 90 91 1;
Now. I have just spoken to the main coder about my issue and he made it clear that what I was doing was setting a scalar by calling a function which of course I was but that this was causing the problem. He also said that I needed to simply make a bunch of functions and not worry about creating any global scalars or arrays.
Everything makes sense to me now but Im still curious what the other monks think.
_
_
_
_
_
_
_
_
_
_
- Jim
Insert clever comment here...
In reply to Re: Re: A lil module creation advice
by snafu
in thread A lil module creation advice
by snafu
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |