Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^3: How to pass an argument to a Module?

by BillKSmith (Chaplain)
on Sep 09, 2012 at 16:49 UTC ( #992607=note: print w/ replies, xml ) Need Help??


in reply to Re^2: How to pass an argument to a Module?
in thread How to pass an argument to a Module?

If you module is a class, you have written a call to a class method. (That is even better than what I had in mind.) If not, the initialize function would have to be written, passed, and called the same way as every other function in the module.

Bill


Comment on Re^3: How to pass an argument to a Module?
Re^4: How to pass an argument to a Module?
by mascip (Pilgrim) on Sep 09, 2012 at 17:01 UTC

    I just tried it on a simple package and it works :o)
    You're right, as it's not a class i'm doing:

    use Mod; Mod::initialize('argument');

    It is more simple than the previous solutions, and does what i need. Thank you !

    It is less 'elegant' though : there is an additional line of code to put in the client code, each time.
    If someone knows how to use IMPORT i'm still interested in learning.

      Despite the Perl6::Export::Attrs pod, IMPORT should just be a plain old sub.

      sub IMPORT { ... }

      Here's a full example:

      use 5.010; use strict; { package Local::MyTest; no thanks; use Perl6::Export::Attrs; sub foobar :Export(:DEFAULT) { return 1; } sub IMPORT { say "in the IMPORT block! Got: @_"; } } use Local::MyTest qw(1 2 3 :DEFAULT); say "YEAH!" if foobar();
      perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://992607]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2014-09-20 09:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (158 votes), past polls