EXPORT and EXPORT_OK question - Page 3

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

Re: EXPORT and EXPORT_OK question

On 07/28/2015 02:01 AM, Rainer Weikusat wrote:
Quoted text here. Click to load it

When I say import, I mean into the resulting assembly code.
I need to learn Perl Speak.

Quoted text here. Click to load it

Would mind you giving me an example?

Thank you for helping me with this.


Re: EXPORT and EXPORT_OK question

  T> I prefer Pin Ball.  I tried going through Perl courses twice.
  T> I do not learn that way.  I actually fell asleep.  I learn
  T> by jumping in both feet and doing something useful I need.

  >> You don't need to know about EXPORT until you're
  >> writing modules - and even then you might not need it,

  T> I will be doing my first module probably sometime this
  T> week. Or at least that is the game plan.

and even then you will likely not need EXPORT. OO modules (which you
haven't flitted to yet) don't export in general. and if you are writing
basic modules with a few subs, just exporting them all is fine. don't
worry about export_ok until you think there could be a problem with
exporting everything.

  >> I've written
  >> dozens of modules over the last fifteen or so years and I've never
  >> used it.

  T> Okay, I will bite.  All of the documentation on modules I
  T> have been reading say I have to use EXPORT or EXPORT_OK so
  T> that the internal functions/subs can be seem by the
  T> calling script.  How are you doing this without EXPORT?

by not using a different namespace (keep it all in main::) is one
idea. are these modules meant to be reused by others? are they dedicated
to this one script? i have larger programs where i don't use namespaces
but i use modules just to organize the code. this module has this stuff
in it and that has that stuff. works fine without exporting as i don't
use a package anywhere. the modules are dedicated to the script and will
never be shared. modules are for organizing code more than anything
else. they can share subs by export, they can be OO, they can be in the
main:: namespace. your choice as always.


Re: EXPORT and EXPORT_OK question

On 07/27/2015 10:27 PM, Uri Guttman wrote:
Quoted text here. Click to load it

Hi Uri,

    They will be used universally.  But, maybe in the future I
will have ones only for specific modules.

    As Mart stated, EXPORT is "suppose" to be used, but is not
enforced.  I should use it anyway, for readability.  That way
I know what I intent to export.

Thank you for helping me with this!


Re: EXPORT and EXPORT_OK question

Quoted text here. Click to load it

I suggest a problem with either the course or the teacher.

Quoted text here. Click to load it

No idea, I've never read EXPORT's documentation, it's never been  
necessary for my > 50k LOC perl currently in production. But, here's  
*a* way of writing a module without it - don't forget, this is Perl,  

package Consignment::Box;
use warnings;use strict;

sub new {return bless {}, shift}
sub len {my $self=shift; $self->= shift; return $self->}
sub wid {my $self=shift; $self->= shift@_; return $self->}
sub dep {my $self=shift; $self->= shift; return $self->}
sub vol {my $self=shift; return $self-> * $self-> * $self->}

(I don't really write modules like this, this is just a proof )

use strict; use warnings; use feature qw/say/;

my $box = Consignment::Box->new;
$box->wid(3); $box->len(4); $box->dep(5);
say $box->vol;

justin@zem:~$ tmp/demo.pl

Quoted text here. Click to load it

Then you are destined to spend a long time in the suburbs of Perl


Justin C, by the sea.

Re: EXPORT and EXPORT_OK question

On 07/28/2015 02:46 AM, Justin C wrote:
Quoted text here. Click to load it

Hi Justin,

I use to fall asleep in Military Tech School, where I could
get into some serious trouble.  My mates use to watch out for
me by kicking me under the table.  Not sure whether it was out
of friendship or because they liked kicking me.  Maybe a little
of both.

The Tech teachers always knew what had happened when I groaned
in pain.  They thought it was pretty funny.  Blew their minds that
I aced their courses.  100%.  The manuals were written better
than the teaching material.  I just read the manuals.  Wonderful
schematics.  I know, so why don't I read perldoc more.

I remember when they thought they had finally stumped me because
I was taking too long trying to solve a problem.  When I
told them that they had jammed the wrong card into the chassis,
it blew their minds.  They dismissed the class to take a break.
We peeked at them through a little window.  Both teachers were
on the floor yanking on the card.  Took them about a half
hour to get it out.  Couldn't hear if they were cussing or not.
Pretty funny to all of us even without the sound effects.

So it is hard to separate me from the course and/or the teacher.
I learn differently.  I am a bit weird.


I fall asleep in church too.  No one to kick me there.  Or
at least, no one who is suppose to enjoy it.  :-)

Re: EXPORT and EXPORT_OK question

On Saturday, 25 July 2015 01:38:40 UTC+5:30, T  wrote:
Quoted text here. Click to load it

Whatever symbols(meaning, functions, variables) in the
@EXPORT array shall be visible in the place where it will be "use-d"
and whatever symbols are put in the @EXPORT_OK array will only
be available upon request. Specifically, let's say in a module the
module writer(NOT the module user) put this in the module's code:

   @EXPORT = qw( f1 f2 f3 );
   @EXPORT_OK = qw( g1 g2 g3 g4 g5);

   print for @File::Basename::EXPORT; --> show me the auto-exported symbols
   print for @File::Basename::EXPORT_OK; --> show me the asked-for symbols  

Then, in your code where you use YourModule, the following 3 different ways

1. use YourModule;               # Import default symbols into my package.
2. use YourModule qw(f2 g5);     # Import listed symbols into my package.
3. use YourModule ();            # Do not import any symbols

Method-1. All of contents of @EXPORT, i.e., f1 f2 f3 will appear in your code.

Method-2. Only f2 & g5 visible. Note: f1/f3 which are default DO NOT show up.

Method-3. Nothing shows up in your code. You have to resort to using the full
          names, like , File::Basename::dirname with this method.

Re: EXPORT and EXPORT_OK question

On 07/25/2015 02:46 AM, sharma__r@hotmail.com wrote:
Quoted text here. Click to load it

Hi Sharma,

I think I was having trouble wrapping my mind around "available
on request", which drew a "what that suppose to mean" from me.

Coming from Modula2, it would have far more understandable if
it said "must be specifically imported by name to be used".

To me "available on request" means that the code will be added to
the parent if I make a call to the function from the parent,
which is exactly the behavior I would expect from @EXPORT.  So
they both seemed exactly the same to me.

Thank you for helping me with this.  I am getting there slowly, but
I am getting there!


Site Timeline