Home > Archive > PERL Beginners > July 2005 > Package/modual question -- more
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Package/modual question -- more
|
|
| Luinrandir 2005-07-25, 5:30 pm |
| 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" <security.department@tele2.ch>
To: <beginners@perl.org>
Sent: Monday, July 25, 2005 10:44 AM
Subject: Re: Package question
> Luinrandir am Montag, 25. Juli 2005 21.42:
>
> or: "uses"
>
>
> ...defined...
>
>
> you have a namespace issue here, see below.
>
be[color=darkred]
>
> 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: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
>
>
>
| |
| Jeff 'japhy' Pinyan 2005-07-25, 5:30 pm |
| On Jul 25, Luinrandir said:
> Question 1:
> should this be a package.pl or a modual.pm?
If you want to be able to source the file via the
use ModuleName;
then the file must end in '.pm'.
> Question 2:
> so I need to
> require 'package.pl';
> but
> use 'modual.pm';
The syntax is
use ModuleName;
with no quotes, and no '.pm' at the end.
> I'm still a bit cloudy on the differences.. other than modual is a package
> but a package is not a modual.
A module is a file with a '.pm' extension. Modules usually define at
least one package, sometimes more. A package is a namespace, a
compartment to hold variables, functions, etc.
> 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?
In your ReadWrite package's WriteData() function, you will get the
arguments from @_. $_[0] will correspond to $filename, and everything
from $_[1] to the end of @_ will correspond to the elements in @Data.
--
Jeff "japhy" Pinyan % How can we ever be the sold short or
RPI Acacia Brother #734 % the cheated, we who for every service
http://japhy.perlmonk.org/ % have long ago been overpaid?
http://www.perlmonks.org/ % -- Meister Eckhart
| |
| Luinrandir 2005-07-25, 10:03 pm |
| Ok.. thats what I thought...
thanks Lou
... in my 5 year mission to wrap my brain around perl.
----- Original Message -----
From: "Jeff 'japhy' Pinyan" <japhy@perlmonk.org>
To: "Luinrandir" <Luinrandir@insight.rr.com>
Cc: <beginners@perl.org>
Sent: Monday, July 25, 2005 2:27 PM
Subject: Re: Package/modual question -- more
> On Jul 25, Luinrandir said:
>
>
> If you want to be able to source the file via the
>
> use ModuleName;
>
> then the file must end in '.pm'.
>
>
> The syntax is
>
> use ModuleName;
>
> with no quotes, and no '.pm' at the end.
>
package[color=darkred]
>
> A module is a file with a '.pm' extension. Modules usually define at
> least one package, sometimes more. A package is a namespace, a
> compartment to hold variables, functions, etc.
>
>
> In your ReadWrite package's WriteData() function, you will get the
> arguments from @_. $_[0] will correspond to $filename, and everything
> from $_[1] to the end of @_ will correspond to the elements in @Data.
>
> --
> Jeff "japhy" Pinyan % How can we ever be the sold short or
> RPI Acacia Brother #734 % the cheated, we who for every service
> http://japhy.perlmonk.org/ % have long ago been overpaid?
> http://www.perlmonks.org/ % -- Meister Eckhart
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
>
>
>
|
|
|
|
|