Hallo again
BTW I am referencing
"Perl, read less learn more" Pg170 to 177

ok I found one problem... I did not have
package::subroutine();
in the main program... now it works, sorta...
I need to pass data to and from the packages.

Question 1:
should this be a package.pl or a modual.pm?

Question 2:
so I need to
require 'package.pl';
but
use 'modual.pm';
I'm still a bit cloudy on the differences.. other than modual is a package
but a package is not a modual.
?????

Question 3:
I am using this.
ReadWrite:WriteData($filename,@Data);
In teh package am I to use $_[0] and $_[1]?
or can I use $filename and @Data?

I know that passing the var $filename and using it as $_[0] works
because I am writing to the filename... but no data....
but then I am using @Data in the package and not $_[1]

This is my next experiment...

Lou


----- Original Message -----
From: "John Doe" <[EMAIL PROTECTED]>
To: <beginners@perl.org>
Sent: Monday, July 25, 2005 10:44 AM
Subject: Re: Package question


> Luinrandir am Montag, 25. Juli 2005 21.42:
> > I am just learning about making and using my own packages and moduals
> >
> >
> > I have a CGI that requires a package.
>
> or: "uses"
>
> > the package is
> > a subroutine that is called on in the main program(CGI)
> > The subroutine works fine as a sub
>
> ...defined...
>
> > in the main program.
> > but when I put it in a package, it does not work.
>
> you have a namespace issue here, see below.
>
> > I thought requiring it (in the first 10 lines of the main program) would
be
> > enough to use is..
> > do I have to call on it?
> >
> >
> > Main program
> > require package
> >
> > do stuff here....
> > subroutine;
> >
> > sub subroutine
> > {
> >     do stuff here
> > }
> >
> > OR---------
> >
> > Main program
> > require package
> >
> > do stuff here....
> > subroutine;
> >
> > sub subroutine
> > {
> >     call package???
> > }
>
> In both code snippets, you redefine subroutine, which is not what you
want.
>
> you probably want:
>
>
> a) the module:
>
> package MyPackage;
> use strict;
> use warnings;
>
> mysub {
> ...
> }
>
> 1;
>
> b) in your main script:
>
> ...
> use MyPackage;  # use your package
> MyPackage::mysub(...);  # call qualified sub from it
> ...
>
>
> You could use the Exporter module to avoid the qualified call of the sub
> defined in your module. I personally prefer to write more and call
qualified
> subs from my modules, because it is then obvious where they are defined
and
> it is easyer to search for them.
>
> See the perl doc
>
> perldoc perlmod
>
> for information about modules and their usage.
>
> joe
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
>
>
>



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to