Hi Rajeev,

On Tue, 16 Oct 2012 22:07:48 -0700 (PDT)
Rajeev Prasad <rp.ne...@yahoo.com> wrote:

> Hello Shlomi,
> 
> thx for the help. I tried and it worked. however I have few
> confusions. I tried it two ways (one yours and one from another
> website)  I am not sure what is different between the two approaches.
> I do not know can you explain pl?
> 
> from: http://www.tutorialspoint.com/perl/perl_modules.htm
> 

I would recommend against learning Perl from random tutorials on the Net,
because they may be old and/or misinformed. For some recommended resources,
see:

1. http://perl-begin.org/ .

2. http://perl-tutorial.org/ .

For reference:

* http://perl-tutorial.org/rejected/


> file: Mymodule.pm
> 

Preferably, it should be "MyModule" instead of "Mymodule" (in CamelCase).

> #!/usr/bin/perl

No need for a sha-bang line in a .pm file.

> package Mymodule;
> 
> use strict;
> use warnings;
> 
> require Exporter;
> our @ISA = qw(Exporter);  # IT WAS FAILING WITH my

It does fail with my, because ISA should be a package scope variable, not
a lexical one. Instead of mangling @ISA directly, you should use the "use
parent" pragma, which would be easier, and less error-prone.

> our @EXPORT = qw(myroutine);
>

@EXPORT will always export myroutine even if you didn't specify it explicitly 
and
so should not be used. @EXPORT is another package-scope variables.
You should use @EXPORT_OK instead.

> ...
> 
> sub myroutine{
> ...
> 
> }
> ....
> 
> 
> 
> file: perlscript.pl
> 
> #!/usr/bin/perl
> 
> use strict;
> use warnings;
> use Template;
> use Mymodule;
> 
> my ($output)=myroutine($input);
> 

Just a note - this will call myroutine in list-context and extract the
first element of the list it returns. Is that what you want?

> 
> 
> 
> 
> 
> then used your method: and it worked, as expected. I am not sure what
> is the diff between two approaches? can you pl help explain? ty.
> 
> file: Mymodule.pm
> 
> #!/usr/bin/perl
> package Mymodule;
> 
> use strict;
> use warnings;
> 
> use parent 'Exporter';
> our @EXPORT_OK = qw(myroutine);
> 
> 
> 
> 
> file:  perlscript.pl
> 
> #!/usr/bin/perl
> 
> use strict;
> use warnings;
> use Template;
> use Mymodule qw(myroutine);
> 
> my ($output)=myroutine($input);
> 
> 

Regards,

        Shlomi Fish

-- 
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
"The Human Hacking Field Guide" - http://shlom.in/hhfg

He says “One and one and one is three”.
Got to be good‐looking ’cause he’s so hard to see.
    — The Beatles, “Come Together”

Please reply to list if it's a mailing list post - http://shlom.in/reply .

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to